JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonNumberFormatVisitor;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
/**
* Container class for serializers used for handling standard JDK-provided types.
*/
@SuppressWarnings("serial")
public class NumberSerializers
{
protected NumberSerializers() { }
public static void addAll(Map<String, JsonSerializer<?>> allDeserializers)
{
final JsonSerializer<?> intS = new IntegerSerializer();
allDeserializers.put(Integer.class.getName(), intS);
allDeserializers.put(Integer.TYPE.getName(), intS);
allDeserializers.put(Long.class.getName(), LongSerializer.instance);
allDeserializers.put(Long.TYPE.getName(), LongSerializer.instance);
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode(_schemaType, true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
if (_isInt) {
JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
if (v2 != null) {
v2.numberType(_numberType);
}
} else {
JsonNumberFormatVisitor v2 = visitor.expectNumberFormat(typeHint);
if (v2 != null) {
v2.numberType(_numberType);
}
}
}
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov,
BeanProperty property) throws JsonMappingException
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> {
if (property != null) {
AnnotatedMember m = property.getMember();
if (m != null) {
JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat(m);
if (format != null) {
switch (format.getShape()) {
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.Iterator;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
import com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase;
@SuppressWarnings("serial")
@JacksonStdImpl
public class IteratorSerializer
extends AsArraySerializerBase<Iterator<?>>
{
public IteratorSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts) {
super(Iterator.class, elemType, staticTyping, vts, null);
}
public IteratorSerializer(IteratorSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public boolean isEmpty(SerializerProvider prov, Iterator<?> value) {
return (value == null) || !value.hasNext();
}
@Override
public boolean hasSingleElement(Iterator<?> value) {
// no really good way to determine (without consuming iterator), so:
return false;
}
@Override
public ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts) {
return new IteratorSerializer(this, _property, vts, _elementSerializer, _unwrapSingle);
}
@Override
public IteratorSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new IteratorSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
@Override
public final void serialize(Iterator<?> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
if (hasSingleElement(value)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray();
serializeContents(value, gen,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.util.*;
/**
* Helper class for {@link BeanSerializerFactory} that is used to
* construct {@link BeanPropertyWriter} instances. Can be sub-classed
* to change behavior.
*/
public class PropertyBuilder
{
final protected SerializationConfig _config;
final protected BeanDescription _beanDesc;
/**
* Default inclusion mode for properties of the POJO for which
* properties are collected; possibly overridden on
* per-property basis.
*/
final protected JsonInclude.Include _defaultInclusion;
final protected AnnotationIntrospector _annotationIntrospector;
/**
* If a property has serialization inclusion value of
* {@link com.fasterxml.jackson.annotation.JsonInclude.Include#NON_DEFAULT},
* we need to know the default value of the bean, to know if property value
* equals default one.
*/
protected Object _defaultBean;
public PropertyBuilder(SerializationConfig config, BeanDescription beanDesc)
{
_config = config;
_beanDesc = beanDesc;
_defaultInclusion = beanDesc.findSerializationInclusion(config.getSerializationInclusion());
_annotationIntrospector = _config.getAnnotationIntrospector();
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
public Annotations getClassAnnotations() {
return _beanDesc.getClassAnnotations();
}
/**
* @param contentTypeSer Optional explicit type information serializer
* to use for contained values (only used for properties that are
* of container type)
*/
protected BeanPropertyWriter buildWriter(SerializerProvider prov,
BeanPropertyDefinition propDef, JavaType declaredType, JsonSerializer<?> ser,
TypeSerializer typeSer, TypeSerializer contentTypeSer,
AnnotatedMember am, boolean defaultUseStaticTyping)
throws JsonMappingException
{
// do we have annotation that forces type to use (to declared type or its super type)?
JavaType serializationType = findSerializationType(am,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> "empty", which in their case means "absent"
if (declaredType.isReferenceType()) {
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
}
break;
case NON_EMPTY:
// always suppress nulls
suppressNulls = true;
// but possibly also 'empty' values:
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
break;
case NON_NULL:
suppressNulls = true;
// fall through
case ALWAYS: // default
default:
// we may still want to suppress empty collections, as per [JACKSON-254]:
if (declaredType.isContainerType()
&& !_config.isEnabled(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS)) {
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
}
break;
}
BeanPropertyWriter bpw = new BeanPropertyWriter(propDef,
am, _beanDesc.getClassAnnotations(), declaredType,
ser, typeSer, serializationType, suppressNulls, valueToSuppress);
// How about custom null serializer?
Object serDef = _annotationIntrospector.findNullSerializer(am);
if (serDef != null) {
bpw.assignNullSerializer(prov.serializerInstance(am, serDef));
}
// And then, handling of unwrapping
NameTransformer unwrapper = _annotationIntrospector.findUnwrappingNameTransformer(am);
if (unwrapper != null) {
bpw = bpw.unwrappingWriter(unwrapper);
}
return bpw;
}
/*
/**********************************************************
/* Helper methods; annotation access
/**********************************************************
*/
/**
* Method that will try to determine statically defined type of property
* being serialized, based on annotations (for overrides), and alternatively
* declared type (if static typing for serialization is enabled).
* If neither can be used (no annotations, dynamic typing), returns null.
*/
protected JavaType findSerializationType(Annotated a, boolean useStaticTyping, JavaType declaredType)
{
// [JACKSON-120]: Check to see if serialization type is fixed
Class<?> serClass = _annotationIntrospector.findSerializationType(a);
if (serClass != null) {
// Must be a super type
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>s,
* let's cache instances by default.
*/
@Override
public boolean isCachable() { return true; }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// Usually should just get string value:
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
String name = p.getText();
Object result = _enumLookup.find(name);
if (result == null) {
return _deserializeAltString(p, ctxt, name);
}
return result;
}
// But let's consider int acceptable as well (if within ordinal range)
if (curr == JsonToken.VALUE_NUMBER_INT) {
// ... unless told not to do that. :-) (as per [JACKSON-412])
_checkFailOnNumber(ctxt);
int index = p.getIntValue();
if (index >= 0 && index <= _enumsByIndex.length) {
return _enumsByIndex[index];
}
if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdNumberException(Integer.valueOf(index), _enumClass(),
"index value outside legal index range [0.."+(_enumsByIndex.length-1)+"]");
}
return null;
}
return _deserializeOther(p, ctxt);
}
private final Object _deserializeAltString(JsonParser p, DeserializationContext ctxt,
String name) throws IOException
{
name = name.trim();
if (name.length() == 0) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
return null;
}
} else {
// [#149]: Allow use of 'String' indexes as well
char c = name.charAt(0);
if (c >= '0' && c <= '9') {
try {
int ix = Integer.parseInt(name);
_checkFailOnNumber(ctxt);
if (ix >= 0 && ix <= _enumsByIndex.length) {
return _enumsByIndex[ix];
}
} catch (NumberFormatException e) {
// fine,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.exc;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Base class for {@link JsonMappingException}s that are specifically related
* to problems related to binding an individual property.
*
* @since 2.3
*/
@SuppressWarnings("serial")
public abstract class PropertyBindingException
extends JsonMappingException
{
/**
* Class that does not contain mapping for the unrecognized property.
*/
protected final Class<?> _referringClass;
/**
*<p>
* Note: redundant information since it is also included in the
* reference path.
*/
protected final String _propertyName;
/**
* Set of ids of properties that are known for the type, if this
* can be statically determined.
*/
protected final Collection<Object> _propertyIds;
/**
* Lazily constructed description of known properties, used for
* constructing actual message if and as needed.
*/
protected transient String _propertiesAsString;
protected PropertyBindingException(String msg, JsonLocation loc,
Class<?> referringClass, String propName,
Collection<Object> propertyIds)
{
super(msg, loc);
_referringClass = referringClass;
_propertyName = propName;
_propertyIds = propertyIds;
}
/*
/**********************************************************
/* Overrides
/**********************************************************
*/
/**
* Somewhat arbitrary limit, but let's try not to create uselessly
* huge error messages
*/
private final static int MAX_DESC_LENGTH = 1000;
@Override
public String getMessageSuffix()
{
String suffix = _propertiesAsString;
if (suffix == null && _propertyIds != null) {
StringBuilder sb = new StringBuilder(100);
int len = _propertyIds.size();
if (len == 1) {
sb.append(" (one known property: \"");
sb.append(String.valueOf(_propertyIds.iterator().next()));
sb.append('"');
} else {
sb.append(" (").append(len).append(" known properties: ");
Iterator<Object> it = _property
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Ids.iterator();
while (it.hasNext()) {
sb.append('"');
sb.append(String.valueOf(it.next()));
sb.append('"');
// one other thing: limit max length
if (sb.length() > MAX_DESC_LENGTH) {
sb.append(" [truncated]");
break;
}
if (it.hasNext()) {
sb.append(", ");
}
}
}
sb.append("])");
_propertiesAsString = suffix = sb.toString();
}
return suffix;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method for accessing type (class) that is missing definition to allow
* binding of the unrecognized property.
*/
public Class<?> getReferringClass() {
return _referringClass;
}
/**
* Convenience method for accessing logical property name that could
* not be mapped. Note that it is the last path reference in the
* underlying path.
*/
public String getPropertyName() {
return _propertyName;
}
public Collection<Object> getKnownPropertyIds()
{
if (_propertyIds == null) {
return null;
}
return Collections.unmodifiableCollection(_propertyIds);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> type this serializer is used for.
*/
public abstract JavaType getContentType();
/**
* Accessor for serializer used for serializing contents
* (List and array elements, Map values etc) of the
* container for which this serializer is used, if it is
* known statically.
* Note that for dynamic types this may return null; if so,
* caller has to instead use {@link #getContentType()} and
* {@link com.fasterxml.jackson.databind.SerializerProvider#findValueSerializer}.
*/
public abstract JsonSerializer<?> getContentSerializer();
/*
/**********************************************************
/* Abstract methods for sub-classes to implement
/**********************************************************
*/
/* Overridden as abstract, to force re-implementation; necessary for all
* collection types.
*/
@Override
@Deprecated
public boolean isEmpty(T value) {
return isEmpty(null, value);
}
// since 2.5: should be declared abstract in future (2.6)
// @Override
// public abstract boolean isEmpty(SerializerProvider prov, T value);
/**
* Method called to determine if the given value (of type handled by
* this serializer) contains exactly one element.
*<p>
* Note: although it might seem sensible to instead define something
* like "getElementCount()" method, this would not work well for
* containers that do not keep track of size (like linked lists may
* not).
*/
public abstract boolean hasSingleElement(T value);
/**
* Method that needs to be implemented to allow construction of a new
* serializer object with given {@link TypeSerializer}, used when
* addition type information is to be embedded.
*/
protected abstract ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts);
/*
/**********************************************************
/* Helper methods for sub-types
/**********************************************************
*/
/**
* Helper method used to encapsulate logic for determining whether there is
* a property annotation that overrides element type; if so, we can
* and need to statically find the serializer.
*
* @since 2.1
*/
protected boolean hasContentTypeAnnotation(SerializerProvider provider,
BeanProperty property)
{
if (property != null) {
AnnotationIntrospector intr = provider.getAnnotationIntrospector();
AnnotatedMember m = property.getMember();
if ((m !=
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.type;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Simple recursive-descent parser for parsing canonical {@link JavaType}
* representations and constructing type instances.
*
* @author tatu
*/
public class TypeParser
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected final TypeFactory _factory;
public TypeParser(TypeFactory f) {
_factory = f;
}
public JavaType parse(String canonical)
throws IllegalArgumentException
{
canonical = canonical.trim();
MyTokenizer tokens = new MyTokenizer(canonical);
JavaType type = parseType(tokens);
// must be end, now
if (tokens.hasMoreTokens()) {
throw _problem(tokens, "Unexpected tokens after complete type");
}
return type;
}
protected JavaType parseType(MyTokenizer tokens)
throws IllegalArgumentException
{
if (!tokens.hasMoreTokens()) {
throw _problem(tokens, "Unexpected end-of-string");
}
Class<?> base = findClass(tokens.nextToken(), tokens);
// either end (ok, non generic type), or generics
if (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
if ("<".equals(token)) {
return _factory._fromParameterizedClass(base, parseTypes(tokens));
}
// can be comma that separates types, or closing '>'
tokens.pushBack(token);
}
return _factory._fromClass(base, null);
}
protected List<JavaType> parseTypes(MyTokenizer tokens)
throws IllegalArgumentException
{
ArrayList<JavaType> types = new ArrayList<JavaType>();
while (tokens.hasMoreTokens()) {
types.add(parseType(tokens));
if (!tokens.hasMoreTokens()) break;
String token = tokens.nextToken();
if (">".equals(token)) return types;
if (!",".equals(token)) {
throw _problem(tokens, "Unexpected token '"+token+"', expected ',' or '>')");
}
}
throw _problem(tokens, "Unexpected end-of-string");
}
protected Class<?> findClass(String className, MyTokenizer tokens)
{
try {
return _factory.find
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
_values = v;
_serializeAsIndex = serializeAsIndex;
}
/**
* Factory method used by {@link com.fasterxml.jackson.databind.ser.BasicSerializerFactory}
* for constructing serializer instance of Enum types.
*
* @since 2.1
*/
@SuppressWarnings("unchecked")
public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config,
BeanDescription beanDesc, JsonFormat.Value format)
{
/* 08-Apr-2015, tatu: As per [databind#749], we can not statically determine
* between name() and toString(), need to construct `EnumValues` with names,
* handle toString() case dynamically (for example)
*/
EnumValues v = EnumValues.constructFromName(config, (Class<Enum<?>>) enumClass);
Boolean serializeAsIndex = _isShapeWrittenUsingIndex(enumClass, format, true);
return new EnumSerializer(v, serializeAsIndex);
}
/**
* To support some level of per-property configuration, we will need
* to make things contextual. We are limited to "textual vs index"
* choice here, however.
*/
@Override
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException
{
if (property != null) {
JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat((Annotated) property.getMember());
if (format != null) {
Boolean serializeAsIndex = _isShapeWrittenUsingIndex(property.getType().getRawClass(), format, false);
if (serializeAsIndex != _serializeAsIndex) {
return new EnumSerializer(_values, serializeAsIndex);
}
}
}
return this;
}
/*
/**********************************************************
/* Extended API for Jackson databind core
/**********************************************************
*/
public EnumValues getEnumValues() { return _values; }
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider serializers)
throws IOException
{
// [JACKSON-684]: serialize as index?
if (_serializeAsIndex(serializers)) {
gen.writeNumber(en.ordinal());
return;
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.deser.std;
import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.PropertyMetadata;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.deser.CreatorProperty;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
/**
* For {@link JsonLocation}, we should be able to just implement
* {@link ValueInstantiator} (not that explicit one would be very
* hard but...)
*/
public class JsonLocationInstantiator extends ValueInstantiator
{
@Override
public String getValueTypeDesc() {
return JsonLocation.class.getName();
}
@Override
public boolean canCreateFromObjectWith() { return true; }
@Override
public CreatorProperty[] getFromObjectArguments(DeserializationConfig config) {
JavaType intType = config.constructType(Integer.TYPE);
JavaType longType = config.constructType(Long.TYPE);
return new CreatorProperty[] {
creatorProp("sourceRef", config.constructType(Object.class), 0),
creatorProp("byteOffset", longType, 1),
creatorProp("charOffset", longType, 2),
creatorProp("lineNr", intType, 3),
creatorProp("columnNr", intType, 4)
};
}
private static CreatorProperty creatorProp(String name, JavaType type, int index) {
return new CreatorProperty(PropertyName.construct(name), type, null,
null, null, null, index, null, PropertyMetadata.STD_REQUIRED);
}
@Override
public Object createFromObjectWith(DeserializationContext ctxt, Object[] args) {
return new JsonLocation(args[0], _long(args[1]), _long(args[2]),
_int(args[3]), _int(args[4]));
}
private final static long _long(Object o) {
return (o == null) ? 0L : ((Number) o).longValue();
}
private final static int _int(Object o) {
return
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Type(_class, _referencedType.withStaticTyping(),
_valueHandler, _typeHandler, true);
}
@Override
protected String buildCanonicalName()
{
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
sb.append('<');
sb.append(_referencedType.toCanonical());
return sb.toString();
}
/*
/**********************************************************
/* Narrow/widen
/**********************************************************
*/
@Override
protected JavaType _narrow(Class<?> subclass)
{
// Should we check that there is a sub-class relationship?
return new ReferenceType(subclass, _referencedType,
_valueHandler, _typeHandler, _asStatic);
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
@Override
public JavaType getReferencedType() {
return _referencedType;
}
@Override
public boolean isReferenceType() {
return true;
}
/*
/**********************************************************
/* Public API overrides
/**********************************************************
*/
@Override
public int containedTypeCount() {
return 1;
}
@Override
public JavaType containedType(int index) {
return (index == 0) ? _referencedType : null;
}
@Override
public String containedTypeName(int index) {
return (index == 0) ? "T" : null;
}
@Override
public Class<?> getParameterSource() {
// Hmmh. For now, assume it's the raw type
return _class;
}
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
return _classSignature(_class, sb, true);
}
@Override
public StringBuilder getGenericSignature(StringBuilder sb)
{
_classSignature(_class, sb, false);
sb.append('<');
sb = _referencedType.getGenericSignature(sb);
sb.append(';');
return sb;
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
return new StringBuilder(40)
.append("[reference type, class ")
.append(buildCanonicalName())
.append('<')
.append(_referencedType)
.append('>')
.append(']')
.toString();
}
@Override
public boolean equals
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ReferenceType other = (ReferenceType) o;
if (other._class != _class) return false;
// Otherwise actually mostly worry about referenced type
return _referencedType.equals(other._referencedType);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
if (_fullName.hasSimpleName(newName) && !_fullName.hasNamespace()) {
return this;
}
return new SimpleBeanPropertyDefinition(_member, new PropertyName(newName),
_introspector, _metadata, _inclusion);
}
@Override
public BeanPropertyDefinition withName(PropertyName newName) {
if (_fullName.equals(newName)) {
return this;
}
return new SimpleBeanPropertyDefinition(_member, newName,
_introspector, _metadata, _inclusion);
}
/**
* @since 2.5
*/
public BeanPropertyDefinition withMetadata(PropertyMetadata metadata) {
if (metadata.equals(_metadata)) {
return this;
}
return new SimpleBeanPropertyDefinition(_member, _fullName,
_introspector, metadata, _inclusion);
}
/**
* @since 2.5
*/
public BeanPropertyDefinition withInclusion(JsonInclude.Include inclusion) {
if (_inclusion == inclusion) {
return this;
}
return new SimpleBeanPropertyDefinition(_member, _fullName,
_introspector, _metadata, inclusion);
}
/*
/**********************************************************
/* Basic property information, name, type
/**********************************************************
*/
@Override
public String getName() { return _fullName.getSimpleName(); }
@Override
public PropertyName getFullName() { return _fullName; }
@Override
public boolean hasName(PropertyName name) {
return _fullName.equals(name);
}
@Override
public String getInternalName() { return getName(); }
@Override
public PropertyName getWrapperName() {
return ((_introspector == null) && (_member != null))
? null : _introspector.findWrapperName(_member);
}
// hmmh. what should we claim here?
@Override public boolean isExplicitlyIncluded() { return false; }
@Override public boolean isExplicitlyNamed() { return false; }
/**
* We will indicate that property is optional, since there is nothing
* to indicate whether it might be required.
*/
@Override
public PropertyMetadata getMetadata() {
return _metadata;
}
@Override
public JsonInclude.Include findInclusion() {
return _inclusion;
}
/*
/**********************************************************
/* Access to
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
*/
/**
* Method that can be used to prune unwanted properties, during
* construction of serializers and deserializers.
* Use with utmost care, if at all...
*
* @since 2.1
*/
public boolean removeProperty(String propName)
{
Iterator<BeanPropertyDefinition> it = _properties().iterator();
while (it.hasNext()) {
BeanPropertyDefinition prop = it.next();
if (prop.getName().equals(propName)) {
it.remove();
return true;
}
}
return false;
}
public boolean addProperty(BeanPropertyDefinition def)
{
// first: ensure we do not have such property
if (hasProperty(def.getFullName())) {
return false;
}
_properties().add(def);
return true;
}
/**
* @since 2.6
*/
public boolean hasProperty(PropertyName name) {
return findProperty(name) != null;
}
/**
* @since 2.6
*/
public BeanPropertyDefinition findProperty(PropertyName name)
{
for (BeanPropertyDefinition prop : _properties()) {
if (prop.hasName(name)) {
return prop;
}
}
return null;
}
/*
/**********************************************************
/* Simple accessors from BeanDescription
/**********************************************************
*/
@Override
public AnnotatedClass getClassInfo() { return _classInfo; }
@Override
public ObjectIdInfo getObjectIdInfo() { return _objectIdInfo; }
@Override
public List<BeanPropertyDefinition> findProperties() {
return _properties();
}
@Override
public AnnotatedMethod findJsonValueMethod() {
return (_propCollector == null) ? null
: _propCollector.getJsonValueMethod();
}
@Override
public Set<String> getIgnoredPropertyNames() {
Set<String> ign = (_propCollector == null) ? null
: _propCollector.getIgnoredPropertyNames();
if (ign == null) {
return Collections.emptySet();
}
return ign;
}
@Override
public boolean hasKnownClassAnnotations() {
return _classInfo.hasAnnotations();
}
@Override
public Annotations getClassAnnotations() {
return _classInfo.getAnnotations();
}
@Override
public TypeBindings bindings
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>AnnotatedMethod> getFactoryMethods()
{
// must filter out anything that clearly is not a factory method
List<AnnotatedMethod> candidates = _classInfo.getStaticMethods();
if (candidates.isEmpty()) {
return candidates;
}
ArrayList<AnnotatedMethod> result = new ArrayList<AnnotatedMethod>();
for (AnnotatedMethod am : candidates) {
if (isFactoryMethod(am)) {
result.add(am);
}
}
return result;
}
@Override
public Constructor<?> findSingleArgConstructor(Class<?>... argTypes)
{
for (AnnotatedConstructor ac : _classInfo.getConstructors()) {
// This list is already filtered to only include accessible
/* (note: for now this is a redundant check; but in future
* that may change; thus leaving here for now)
*/
if (ac.getParameterCount() == 1) {
Class<?> actArg = ac.getRawParameterType(0);
for (Class<?> expArg : argTypes) {
if (expArg == actArg) {
return ac.getAnnotated();
}
}
}
}
return null;
}
@Override
public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
if (isFactoryMethod(am)) {
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
// And one that matches what we would pass in
if (actualArgType.isAssignableFrom(expArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
protected boolean isFactoryMethod(AnnotatedMethod am)
{
/* First: return type must be compatible with the introspected class
* (i.e. allowed to be sub-class, although usually is the same
* class)
*/
Class<?> rt = am.getRawReturnType();
if (!getBeanClass().isAssignableFrom(rt)) {
return false;
}
/* Also: must be a recognized factory method, meaning:
* (a) marked with @JsonCreator annotation, or
* (b) "valueOf"
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> (at this point, need not be public)
*/
if (_annotationIntrospector.hasCreatorAnnotation(am)) {
return true;
}
final String name = am.getName();
if ("valueOf".equals(name)) {
return true;
}
// [Issue#208] Also accept "fromString()", if takes String or CharSequence
if ("fromString".equals(name)) {
if (1 == am.getParameterCount()) {
Class<?> cls = am.getRawParameterType(0);
if (cls == String.class || CharSequence.class.isAssignableFrom(cls)) {
return true;
}
}
}
return false;
}
/**
* @deprecated Since 2.4, use <code>findCreatorParameterNames()</code> instead.
*/
@Deprecated
public List<String> findCreatorPropertyNames()
{
List<PropertyName> params = findCreatorParameterNames();
if (params.isEmpty()) {
return Collections.emptyList();
}
List<String> result = new ArrayList<String>(params.size());
for (PropertyName name : params) {
result.add(name.getSimpleName());
}
return result;
}
/**
* @deprecated Since 2.5, does not seem to be used at all.
*/
@Deprecated
public List<PropertyName> findCreatorParameterNames()
{
for (int i = 0; i < 2; ++i) {
List<? extends AnnotatedWithParams> l = (i == 0)
? getConstructors() : getFactoryMethods();
for (AnnotatedWithParams creator : l) {
int argCount = creator.getParameterCount();
if (argCount < 1) continue;
PropertyName name = _findCreatorPropertyName(creator.getParameter(0));
if (name == null || name.isEmpty()) {
continue;
}
List<PropertyName> names = new ArrayList<PropertyName>();
names.add(name);
for (int p = 1; p < argCount; ++p) {
name = _findCreatorPropertyName(creator.getParameter(p));
names.add(name);
}
return names;
}
}
return Collections.emptyList();
}
protected PropertyName _findCreatorPropertyName(AnnotatedParameter param)
{
PropertyName name = _annotationIntros
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>pector.findNameForDeserialization(param);
if (name == null || name.isEmpty()) {
String str = _annotationIntrospector.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
name = PropertyName.construct(str);
}
}
return name;
}
/*
/**********************************************************
/* Introspection for deserialization, other
/**********************************************************
*/
@Override
public Class<?> findPOJOBuilder() {
return (_annotationIntrospector == null) ?
null : _annotationIntrospector.findPOJOBuilder(_classInfo);
}
@Override
public JsonPOJOBuilder.Value findPOJOBuilderConfig()
{
return (_annotationIntrospector == null) ?
null : _annotationIntrospector.findPOJOBuilderConfig(_classInfo);
}
@Override
public Converter<Object,Object> findDeserializationConverter()
{
if (_annotationIntrospector == null) {
return null;
}
return _createConverter(_annotationIntrospector.findDeserializationConverter(_classInfo));
}
/*
/**********************************************************
/* Helper methods for field introspection
/**********************************************************
*/
/**
* @param ignoredProperties (optional) names of properties to ignore;
* any fields that would be recognized as one of these properties
* is ignored.
* @param forSerialization If true, will collect serializable property
* fields; if false, deserializable
*
* @return Ordered Map with logical property name as key, and
* matching field as value.
*/
public LinkedHashMap<String,AnnotatedField> _findPropertyFields(
Collection<String> ignoredProperties, boolean forSerialization)
{
LinkedHashMap<String,AnnotatedField> results = new LinkedHashMap<String,AnnotatedField>();
for (BeanPropertyDefinition property : _properties()) {
AnnotatedField f = property.getField();
if (f != null) {
String name = property.getName();
if (ignoredProperties != null) {
if (ignoredProperties.contains(name)) {
continue;
}
}
results.put(name, f);
}
}
return results;
}
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
@SuppressWarnings("unchecked")
public Converter<Object,Object>
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> ClassNotFoundException
{
// [JACKSON-597]: support primitive types (and void)
if (className.indexOf('.') < 0) {
if ("int".equals(className)) return Integer.TYPE;
if ("long".equals(className)) return Long.TYPE;
if ("float".equals(className)) return Float.TYPE;
if ("double".equals(className)) return Double.TYPE;
if ("boolean".equals(className)) return Boolean.TYPE;
if ("byte".equals(className)) return Byte.TYPE;
if ("char".equals(className)) return Character.TYPE;
if ("short".equals(className)) return Short.TYPE;
if ("void".equals(className)) return Void.TYPE;
}
// Two-phase lookup: first using context ClassLoader; then default
Throwable prob = null;
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader != null) {
try {
return Class.forName(className, true, loader);
} catch (Exception e) {
prob = getRootCause(e);
}
}
try {
return Class.forName(className);
} catch (Exception e) {
if (prob == null) {
prob = getRootCause(e);
}
}
if (prob instanceof RuntimeException) {
throw (RuntimeException) prob;
}
throw new ClassNotFoundException(prob.getMessage(), prob);
}
/*
/**********************************************************
/* Method type detection methods
/**********************************************************
*/
/**
* @deprecated Since 2.6 not used; may be removed before 3.x
*/
@Deprecated // since 2.6
public static boolean hasGetterSignature(Method m)
{
// First: static methods can't be getters
if (Modifier.isStatic(m.getModifiers())) {
return false;
}
// Must take no args
Class<?>[] pts = m.getParameterTypes();
if (pts != null && pts.length != 0) {
return false;
}
// Can't be a void method
if (Void.TYPE == m.getReturnType()) {
return false;
}
// Otherwise looks ok:
return true;
}
/*
/**********************************************************
/* Exception handling
/**********************************************************
*/
/**
* Method that can be used to find the "root
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
/**********************************************************
*/
/**
* Method that can be called to try to create an instantiate of
* specified type. Instantiation is done using default no-argument
* constructor.
*
* @param canFixAccess Whether it is possible to try to change access
* rights of the default constructor (in case it is not publicly
* accessible) or not.
*
* @throws IllegalArgumentException If instantiation fails for any reason;
* except for cases where constructor throws an unchecked exception
* (which will be passed as is)
*/
public static <T> T createInstance(Class<T> cls, boolean canFixAccess)
throws IllegalArgumentException
{
Constructor<T> ctor = findConstructor(cls, canFixAccess);
if (ctor == null) {
throw new IllegalArgumentException("Class "+cls.getName()+" has no default (no arg) constructor");
}
try {
return ctor.newInstance();
} catch (Exception e) {
ClassUtil.unwrapAndThrowAsIAE(e, "Failed to instantiate class "+cls.getName()+", problem: "+e.getMessage());
return null;
}
}
public static <T> Constructor<T> findConstructor(Class<T> cls, boolean canFixAccess)
throws IllegalArgumentException
{
try {
Constructor<T> ctor = cls.getDeclaredConstructor();
if (canFixAccess) {
checkAndFixAccess(ctor);
} else {
// Has to be public...
if (!Modifier.isPublic(ctor.getModifiers())) {
throw new IllegalArgumentException("Default constructor for "+cls.getName()+" is not accessible (non-public?): not allowed to try modify access via Reflection: can not instantiate type");
}
}
return ctor;
} catch (NoSuchMethodException e) {
;
} catch (Exception e) {
ClassUtil.unwrapAndThrowAsIAE(e, "Failed to find default constructor of class "+cls.getName()+", problem: "+e.getMessage());
}
return null;
}
/*
/**********************************************************
/* Primitive type support
/**********************************************************
*/
/**
* Helper method used to get default value for wrappers used for primitive types
* (0 for Integer etc)
*/
public static Object defaultValue(Class<?> cls)
{
if (cls == Integer.TYPE) {
return Integer.valueOf
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>(0);
}
if (cls == Long.TYPE) {
return Long.valueOf(0L);
}
if (cls == Boolean.TYPE) {
return Boolean.FALSE;
}
if (cls == Double.TYPE) {
return Double.valueOf(0.0);
}
if (cls == Float.TYPE) {
return Float.valueOf(0.0f);
}
if (cls == Byte.TYPE) {
return Byte.valueOf((byte) 0);
}
if (cls == Short.TYPE) {
return Short.valueOf((short) 0);
}
if (cls == Character.TYPE) {
return '\0';
}
throw new IllegalArgumentException("Class "+cls.getName()+" is not a primitive type");
}
/**
* Helper method for finding wrapper type for given primitive type (why isn't
* there one in JDK?)
*/
public static Class<?> wrapperType(Class<?> primitiveType)
{
if (primitiveType == Integer.TYPE) {
return Integer.class;
}
if (primitiveType == Long.TYPE) {
return Long.class;
}
if (primitiveType == Boolean.TYPE) {
return Boolean.class;
}
if (primitiveType == Double.TYPE) {
return Double.class;
}
if (primitiveType == Float.TYPE) {
return Float.class;
}
if (primitiveType == Byte.TYPE) {
return Byte.class;
}
if (primitiveType == Short.TYPE) {
return Short.class;
}
if (primitiveType == Character.TYPE) {
return Character.class;
}
throw new IllegalArgumentException("Class "+primitiveType.getName()+" is not a primitive type");
}
/*
/**********************************************************
/* Access checking/handling methods
/**********************************************************
*/
/**
* Method called to check if we can use the passed method or constructor
* (wrt access restriction -- public methods can be called, others
* usually not); and if not, if there is a work-around for
* the problem.
*/
public static void checkAndFixAccess(Member member)
{
// We know all members are also accessible objects...
AccessibleObject ao = (AccessibleObject) member;
/* 14-Jan-2009
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>, tatu: It seems safe and potentially beneficial to
* always to make it accessible (latter because it will force
* skipping checks we have no use for...), so let's always call it.
*/
//if (!ao.isAccessible()) {
try {
ao.setAccessible(true);
} catch (SecurityException se) {
/* 17-Apr-2009, tatu: Related to [JACKSON-101]: this can fail on
* platforms like EJB and Google App Engine); so let's
* only fail if we really needed it...
*/
if (!ao.isAccessible()) {
Class<?> declClass = member.getDeclaringClass();
throw new IllegalArgumentException("Can not access "+member+" (from class "+declClass.getName()+"; failed to set access: "+se.getMessage());
}
}
//}
}
/*
/**********************************************************
/* Enum type detection
/**********************************************************
*/
/**
* Helper method that can be used to dynamically figure out
* enumeration type of given {@link EnumSet}, without having
* access to its declaration.
* Code is needed to work around design flaw in JDK.
*/
public static Class<? extends Enum<?>> findEnumType(EnumSet<?> s)
{
// First things first: if not empty, easy to determine
if (!s.isEmpty()) {
return findEnumType(s.iterator().next());
}
// Otherwise need to locate using an internal field
return EnumTypeLocator.instance.enumTypeFor(s);
}
/**
* Helper method that can be used to dynamically figure out
* enumeration type of given {@link EnumSet}, without having
* access to its declaration.
* Code is needed to work around design flaw in JDK.
*/
public static Class<? extends Enum<?>> findEnumType(EnumMap<?,?> m)
{
if (!m.isEmpty()) {
return findEnumType(m.keySet().iterator().next());
}
// Otherwise need to locate using an internal field
return EnumTypeLocator.instance.enumTypeFor(m);
}
/**
* Helper method that can be used to dynamically figure out formal
* enumeration type (class) for given enumeration. This is either
* class of enum instance (for "simple" enumerations
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>**
/* Helper classes
/**********************************************************
*/
/**
* Inner class used to contain gory details of how we can determine
* details of instances of common JDK types like {@link EnumMap}s.
*/
private static class EnumTypeLocator
{
final static EnumTypeLocator instance = new EnumTypeLocator();
private final Field enumSetTypeField;
private final Field enumMapTypeField;
private EnumTypeLocator() {
//JDK uses following fields to store information about actual Enumeration
// type for EnumSets, EnumMaps...
enumSetTypeField = locateField(EnumSet.class, "elementType", Class.class);
enumMapTypeField = locateField(EnumMap.class, "elementType", Class.class);
}
@SuppressWarnings("unchecked")
public Class<? extends Enum<?>> enumTypeFor(EnumSet<?> set)
{
if (enumSetTypeField != null) {
return (Class<? extends Enum<?>>) get(set, enumSetTypeField);
}
throw new IllegalStateException("Can not figure out type for EnumSet (odd JDK platform?)");
}
@SuppressWarnings("unchecked")
public Class<? extends Enum<?>> enumTypeFor(EnumMap<?,?> set)
{
if (enumMapTypeField != null) {
return (Class<? extends Enum<?>>) get(set, enumMapTypeField);
}
throw new IllegalStateException("Can not figure out type for EnumMap (odd JDK platform?)");
}
private Object get(Object bean, Field field)
{
try {
return field.get(bean);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
private static Field locateField(Class<?> fromClass, String expectedName, Class<?> type)
{
Field found = null;
// First: let's see if we can find exact match:
Field[] fields = fromClass.getDeclaredFields();
for (Field f : fields) {
if (expectedName.equals(f.getName()) && f.getType() == type) {
found = f;
break;
}
}
// And if not, if there is just one field with the type, that field
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> return;
}
// if it wasn't, add and check subtypes recursively
collectedSubtypes.put(namedType, namedType);
Collection<NamedType> st = ai.findSubtypes(annotatedType);
if (st != null && !st.isEmpty()) {
for (NamedType subtype : st) {
AnnotatedClass subtypeClass = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), ai, config);
_collectAndResolve(subtypeClass, subtype, config, ai, collectedSubtypes);
}
}
}
/**
* Method called to find subtypes for a specific type (class), using
* type id as the unique key (in case of conflicts).
*/
protected void _collectAndResolveByTypeId(AnnotatedClass annotatedType, NamedType namedType,
MapperConfig<?> config,
Set<Class<?>> typesHandled, Map<String,NamedType> byName)
{
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
if (!namedType.hasName()) {
String name = ai.findTypeName(annotatedType);
if (name != null) {
namedType = new NamedType(namedType.getType(), name);
}
}
if (namedType.hasName()) {
byName.put(namedType.getName(), namedType);
}
// only check subtypes if this type hadn't yet been handled
if (typesHandled.add(namedType.getType())) {
Collection<NamedType> st = ai.findSubtypes(annotatedType);
if (st != null && !st.isEmpty()) {
for (NamedType subtype : st) {
AnnotatedClass subtypeClass = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), ai, config);
_collectAndResolveByTypeId(subtypeClass, subtype, config, typesHandled, byName);
}
}
}
}
/**
* Helper method used for merging explicitly named types and handled classes
* without explicit names.
*/
protected Collection<NamedType> _combineNamedAndUnnamed(Set<Class<?>> typesHandled,
Map<String,NamedType> byName)
{
ArrayList<NamedType> result = new ArrayList<NamedType>(byName.values());
// Ok, so... we will figure out which classes have no explicitly assigned name,
// by removing Classes
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>+SAMPLE_SPEC_VALUE_TN_ID4+"]\n"
+" }"
+"}"
;
/*
/**********************************************************
/* Helper classes (beans)
/**********************************************************
*/
/**
* Sample class from Jackson tutorial ("JacksonInFiveMinutes")
*/
protected static class FiveMinuteUser {
public enum Gender { MALE, FEMALE };
public static class Name
{
private String _first, _last;
public Name() { }
public Name(String f, String l) {
_first = f;
_last = l;
}
public String getFirst() { return _first; }
public String getLast() { return _last; }
public void setFirst(String s) { _first = s; }
public void setLast(String s) { _last = s; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
Name other = (Name) o;
return _first.equals(other._first) && _last.equals(other._last);
}
}
private Gender _gender;
private Name _name;
private boolean _isVerified;
private byte[] _userImage;
public FiveMinuteUser() { }
public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data)
{
_name = new Name(first, last);
_isVerified = verified;
_gender = g;
_userImage = data;
}
public Name getName() { return _name; }
public boolean isVerified() { return _isVerified; }
public Gender getGender() { return _gender; }
public byte[] getUserImage() { return _userImage; }
public void setName(Name n) { _name = n; }
public void setVerified(boolean b) { _isVerified = b; }
public void setGender(Gender g) { _gender = g; }
public void setUserImage(byte[] b) { _userImage = b; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> false;
FiveMinuteUser other = (FiveMinuteUser) o;
if (_isVerified != other._isVerified) return false;
if (_gender != other._gender) return false;
if (!_name.equals(other._name)) return false;
byte[] otherImage = other._userImage;
if (otherImage.length != _userImage.length) return false;
for (int i = 0, len = _userImage.length; i < len; ++i) {
if (_userImage[i] != otherImage[i]) {
return false;
}
}
return true;
}
}
/*
/**********************************************************
/* High-level helpers
/**********************************************************
*/
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents)
throws IOException
{
verifyJsonSpecSampleDoc(jp, verifyContents, true);
}
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents,
boolean requireNumbers)
throws IOException
{
if (!jp.hasCurrentToken()) {
jp.nextToken();
}
assertToken(JsonToken.START_OBJECT, jp.getCurrentToken()); // main object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Image'
if (verifyContents) {
verifyFieldName(jp, "Image");
}
assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'image' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width'
if (verifyContents) {
verifyFieldName(jp, "Width");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_WIDTH);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height'
if (verifyContents) {
verifyFieldName(jp, "Height");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_HEIGHT);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Title'
if (verifyContents) {
verifyFieldName(jp, "Title");
}
assertToken(JsonToken.VALUE_STRING
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>_VALUE_TN_ID3);
}
verifyIntToken(jp.nextToken(), requireNumbers); // ids[3]
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_TN_ID4);
}
assertToken(JsonToken.END_ARRAY, jp.nextToken()); // 'ids' array
assertToken(JsonToken.END_OBJECT, jp.nextToken()); // 'image' object
assertToken(JsonToken.END_OBJECT, jp.nextToken()); // main object
}
private void verifyIntToken(JsonToken t, boolean requireNumbers)
{
if (t == JsonToken.VALUE_NUMBER_INT) {
return;
}
if (requireNumbers) { // to get error
assertToken(JsonToken.VALUE_NUMBER_INT, t);
}
// if not number, must be String
if (t != JsonToken.VALUE_STRING) {
fail("Expected INT or STRING value, got "+t);
}
}
protected void verifyFieldName(JsonParser jp, String expName)
throws IOException
{
assertEquals(expName, jp.getText());
assertEquals(expName, jp.getCurrentName());
}
protected void verifyIntValue(JsonParser jp, long expValue)
throws IOException
{
// First, via textual
assertEquals(String.valueOf(expValue), jp.getText());
}
/**
* Method that checks whether Unit tests appear to run from Ant build
* scripts.
*
* @since 1.6
*/
protected static boolean runsFromAnt() {
return "true".equals(System.getProperty("FROM_ANT"));
}
/*
/**********************************************************
/* Parser/generator construction
/**********************************************************
*/
protected JsonParser createParserUsingReader(String input)
throws IOException, JsonParseException
{
return createParserUsingReader(new JsonFactory(), input);
}
protected JsonParser createParserUsingReader(JsonFactory f, String input)
throws IOException, JsonParseException
{
return f.createParser(new StringReader(input));
}
protected JsonParser createParserUsingStream(String input, String encoding)
throws IOException, JsonParseException
{
return createParserUsingStream(new JsonFactory(), input, encoding);
}
protected JsonParser createParserUsingStream(JsonFactory f,
String input
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> esc) {
return (characterEscapes == esc) ? this
: new GeneratorSettings(prettyPrinter, schema, esc, rootValueSeparator);
}
public GeneratorSettings withRootValueSeparator(String sep) {
if (sep == null) {
if (rootValueSeparator == null) {
return this;
}
} else if (sep.equals(rootValueSeparator)) {
return this;
}
return new GeneratorSettings(prettyPrinter, schema, characterEscapes,
(sep == null) ? null : new SerializedString(sep));
}
public GeneratorSettings withRootValueSeparator(SerializableString sep) {
if (sep == null) {
if (rootValueSeparator == null) {
return this;
}
} else {
if (rootValueSeparator != null
&& sep.getValue().equals(rootValueSeparator.getValue())) {
return this;
}
}
return new GeneratorSettings(prettyPrinter, schema, characterEscapes, sep);
}
/**
* @since 2.6
*/
public void initialize(JsonGenerator gen)
{
PrettyPrinter pp = prettyPrinter;
if (prettyPrinter != null) {
if (pp == NULL_PRETTY_PRINTER) {
gen.setPrettyPrinter(null);
} else {
if (pp instanceof Instantiatable<?>) {
pp = (PrettyPrinter) ((Instantiatable<?>) pp).createInstance();
}
gen.setPrettyPrinter(pp);
}
}
if (characterEscapes != null) {
gen.setCharacterEscapes(characterEscapes);
}
if (schema != null) {
gen.setSchema(schema);
}
if (rootValueSeparator != null) {
gen.setRootValueSeparator(rootValueSeparator);
}
}
}
/**
* As a minor optimization, we will make an effort to pre-fetch a serializer,
* or at least relevant <code>TypeSerializer</code>, if given enough
* information.
*
* @since 2.5
*/
public final static class Prefetch
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public final static Prefetch empty = new Prefetch(null, null, null);
/**
* Specified root serialization type to use; can be same
* as runtime type
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>, but usually one of its super types
* (parent class or interface it implements).
*/
private final JavaType rootType;
/**
* We may pre-fetch serializer if {@link #rootType}
* is known, and if so, reuse it afterwards.
* This allows avoiding further serializer lookups and increases
* performance a bit on cases where readers are reused.
*/
private final JsonSerializer<Object> valueSerializer;
/**
* When dealing with polymorphic types, we can not pre-fetch
* serializer, but can pre-fetch {@link TypeSerializer}.
*/
private final TypeSerializer typeSerializer;
private Prefetch(JavaType rootT,
JsonSerializer<Object> ser, TypeSerializer typeSer)
{
rootType = rootT;
valueSerializer = ser;
typeSerializer = typeSer;
}
public Prefetch forRootType(ObjectWriter parent, JavaType newType) {
// First: if nominal type not defined, or trivial (java.lang.Object),
// not thing much to do
boolean noType = (newType == null) || newType.isJavaLangObject();
if (noType) {
if ((rootType == null) || (valueSerializer == null)) {
return this;
}
return new Prefetch(null, null, typeSerializer);
}
if (newType.equals(rootType)) {
return this;
}
if (parent.isEnabled(SerializationFeature.EAGER_SERIALIZER_FETCH)) {
DefaultSerializerProvider prov = parent._serializerProvider();
// 17-Dec-2014, tatu: Need to be bit careful here; TypeSerializers are NOT cached,
// so although it'd seem like a good idea to look for those first, and avoid
// serializer for polymorphic types, it is actually more efficient to do the
// reverse here.
try {
JsonSerializer<Object> ser = prov.findTypedValueSerializer(newType, true, null);
// Important: for polymorphic types, "unwrap"...
if (ser instanceof TypeWrappedSerializer) {
return new Prefetch(newType, null,
((TypeWrappedSerializer) ser).typeSerializer());
}
return new Prefetch(newType, ser, null);
} catch (JsonProcessingException e) {
// need to
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> swallow?
;
}
}
return new Prefetch(null, null, typeSerializer);
}
public final JsonSerializer<Object> getValueSerializer() {
return valueSerializer;
}
public final TypeSerializer getTypeSerializer() {
return typeSerializer;
}
public boolean hasSerializer() {
return (valueSerializer != null) || (typeSerializer != null);
}
public void serialize(JsonGenerator gen, Object value, DefaultSerializerProvider prov)
throws IOException
{
if (typeSerializer != null) {
prov.serializePolymorphic(gen, value, rootType, valueSerializer, typeSerializer);
return;
}
if (valueSerializer != null) {
prov.serializeValue(gen, value, rootType, valueSerializer);
return;
}
prov.serializeValue(gen, value);
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> != null) {
ser = provider.serializerInstance(m, serDef);
}
}
JsonFormat.Value format = property.findFormatOverrides(intr);
if (format != null) {
unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
}
}
if (ser == null) {
ser = _serializer;
}
// #124: May have a content converter
ser = findConvertingContentSerializer(provider, property, ser);
if (ser == null) {
ser = provider.findValueSerializer(String.class, property);
} else {
ser = provider.handleSecondaryContextualization(ser, property);
}
// Optimization: default serializer just writes String, so we can avoid a call:
if (isDefaultSerializer(ser)) {
ser = null;
}
// note: will never have TypeSerializer, because Strings are "natural" type
if ((ser == _serializer) && (unwrapSingle == _unwrapSingle)) {
return this;
}
return _withResolved(property, ser, unwrapSingle);
}
@Deprecated // since 2.5
@Override
public boolean isEmpty(T value) {
return isEmpty(null, value);
}
@Override
public boolean isEmpty(SerializerProvider provider, T value) {
return (value == null) || (value.size() == 0);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", contentSchema());
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
acceptContentVisitor(visitor.expectArrayFormat(typeHint));
}
/*
/**********************************************************
/* Abstract methods for sub-classes to implement
/**********************************************************
*/
protected abstract JsonNode contentSchema();
protected abstract void acceptContentVisitor(JsonArrayFormatVisitor visitor)
throws JsonMappingException;
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> || injectables.isEmpty()) ? null
: injectables.toArray(new ValueInjector[injectables.size()]);
_objectIdReader = builder.getObjectIdReader();
_nonStandardCreation = (_unwrappedPropertyHandler != null)
|| _valueInstantiator.canCreateUsingDelegate()
|| _valueInstantiator.canCreateFromObjectWith()
|| !_valueInstantiator.canCreateUsingDefault()
;
// Any transformation we may need to apply?
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
_serializationShape = (format == null) ? null : format.getShape();
_needViewProcesing = hasViews;
_vanillaProcessing = !_nonStandardCreation
&& (_injectables == null)
&& !_needViewProcesing
// also, may need to reorder stuff if we expect Object Id:
&& (_objectIdReader == null)
;
}
protected BeanDeserializerBase(BeanDeserializerBase src) {
this(src, src._ignoreAllUnknown);
}
protected BeanDeserializerBase(BeanDeserializerBase src, boolean ignoreAllUnknown)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_propertyBasedCreator = src._propertyBasedCreator;
_beanProperties = src._beanProperties;
_backRefs = src._backRefs;
_ignorableProps = src._ignorableProps;
_ignoreAllUnknown = ignoreAllUnknown;
_anySetter = src._anySetter;
_injectables = src._injectables;
_objectIdReader = src._objectIdReader;
_nonStandardCreation = src._nonStandardCreation;
_unwrappedPropertyHandler = src._unwrappedPropertyHandler;
_needViewProcesing = src._needViewProcesing;
_serializationShape = src._serializationShape;
_vanillaProcessing = src._vanillaProcessing;
}
protected BeanDeserializerBase(BeanDeserializerBase src, NameTransformer unwrapper)
{
super(src._beanType);
_classAnnotations = src._classAnnotations;
_beanType = src._beanType;
_valueInstantiator = src._valueInstantiator;
_delegateDeserializer = src._delegateDeserializer;
_property
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS><?> type = actualType; type != null; type = type.getSuperclass()) {
if (type.getName().equals(classNameToImplement)) {
return true;
}
// or maybe one of super-interfaces
if (hasInterface(type, classNameToImplement)) {
return true;
}
}
return false;
}
private boolean hasInterface(Class<?> type, String interfaceToImplement)
{
Class<?>[] interfaces = type.getInterfaces();
for (Class<?> iface : interfaces) {
if (iface.getName().equals(interfaceToImplement)) {
return true;
}
}
// maybe super-interface?
for (Class<?> iface : interfaces) {
if (hasInterface(iface, interfaceToImplement)) {
return true;
}
}
return false;
}
private boolean hasSupertypeStartingWith(Class<?> rawType, String prefix)
{
// first, superclasses
for (Class<?> supertype = rawType.getSuperclass(); supertype != null; supertype = supertype.getSuperclass()) {
if (supertype.getName().startsWith(prefix)) {
return true;
}
}
// then interfaces
for (Class<?> cls = rawType; cls != null; cls = cls.getSuperclass()) {
if (hasInterfaceStartingWith(cls, prefix)) {
return true;
}
}
return false;
}
private boolean hasInterfaceStartingWith(Class<?> type, String prefix)
{
Class<?>[] interfaces = type.getInterfaces();
for (Class<?> iface : interfaces) {
if (iface.getName().startsWith(prefix)) {
return true;
}
}
// maybe super-interface?
for (Class<?> iface : interfaces) {
if (hasInterfaceStartingWith(iface, prefix)) {
return true;
}
}
return false;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
throws IOException
{
// [JACKSON-87]: Support both numeric timestamps and textual
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
jgen.writeNumber(timestamp);
} else {
jgen.writeString(_dateFormat().format(new Date(timestamp)));
}
}
/**
* Method that will handle serialization of Date(-like) values, using
* {@link SerializationConfig} settings to determine expected serialization
* behavior.
* Note: date here means "full" date, that is, date AND time, as per
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(Date date, JsonGenerator gen)
throws IOException
{
// [JACKSON-87]: Support both numeric timestamps and textual
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
gen.writeNumber(date.getTime());
} else {
gen.writeString(_dateFormat().format(date));
}
}
/**
* Method that will handle serialization of Dates used as {@link java.util.Map} keys,
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen)
throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
gen.writeFieldName(String.valueOf(timestamp));
} else {
gen.writeFieldName(_dateFormat().format(new Date(timestamp)));
}
}
/**
* Method that will handle serialization of Dates used as {@link java.util.Map} keys,
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(Date date, JsonGenerator gen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
gen.writeFieldName(String.valueOf(date.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Calendar;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
/**
* Standard serializer for {@link java.util.Calendar}.
* As with other time/date types, is configurable to produce timestamps
* (standard Java 64-bit timestamp) or textual formats (usually ISO-8601).
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class CalendarSerializer
extends DateTimeSerializerBase<Calendar>
{
public static final CalendarSerializer instance = new CalendarSerializer();
public CalendarSerializer() { this(null, null); }
public CalendarSerializer(Boolean useTimestamp, DateFormat customFormat) {
super(Calendar.class, useTimestamp, customFormat);
}
@Override
public CalendarSerializer withFormat(Boolean timestamp, DateFormat customFormat) {
return new CalendarSerializer(timestamp, customFormat);
}
@Override
protected long _timestamp(Calendar value) {
return (value == null) ? 0L : value.getTimeInMillis();
}
@Override
public void serialize(Calendar value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
if (_asTimestamp(provider)) {
jgen.writeNumber(_timestamp(value));
} else if (_customFormat != null) {
// 21-Feb-2011, tatu: not optimal, but better than alternatives:
synchronized (_customFormat) {
// _customformat cannot parse Calendar, so Date should be passed
jgen.writeString(_customFormat.format(value.getTime()));
}
} else {
provider.defaultSerializeDateValue(value.getTime(), jgen);
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* This concrete value class is used to contain boolean (true / false)
* values. Only two instances are ever created, to minimize memory
* usage.
*/
public class BooleanNode
extends ValueNode
{
// // Just need two instances...
public final static BooleanNode TRUE = new BooleanNode(true);
public final static BooleanNode FALSE = new BooleanNode(false);
private final boolean _value;
private BooleanNode(boolean v) { _value = v; }
public static BooleanNode getTrue() { return TRUE; }
public static BooleanNode getFalse() { return FALSE; }
public static BooleanNode valueOf(boolean b) { return b ? TRUE : FALSE; }
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.BOOLEAN;
}
@Override public JsonToken asToken() {
return _value ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
}
@Override
public boolean booleanValue() {
return _value;
}
@Override
public String asText() {
return _value ? "true" : "false";
}
@Override
public boolean asBoolean() {
return _value;
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value;
}
@Override
public int asInt(int defaultValue) {
return _value ? 1 : 0;
}
@Override
public long asLong(long defaultValue) {
return _value ? 1L : 0L;
}
@Override
public double asDouble(double defaultValue) {
return _value ? 1.0 : 0.0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeBoolean(_value);
}
@Override
public boolean equals(Object o)
{
/* 11-Mar-2013, tatu: Apparently ClassLoaders can manage to load
* different instances, rendering identity comparisons broken.
* So let's use value instead.
*/
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>(p, ctxt, result);
return result;
}
continue;
}
// other property? needs buffering
Object actualKey = _keyDeserializer.deserializeKey(key, ctxt);
Object value;
try {
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(p, ctxt);
} else {
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
}
} catch (Exception e) {
wrapAndThrow(e, _mapType.getRawClass(), key);
return null;
}
buffer.bufferMapProperty(actualKey, value);
}
// end of JSON object?
// if so, can just construct and leave...
try {
return (Map<Object,Object>)creator.build(ctxt, buffer);
} catch (Exception e) {
wrapAndThrow(e, _mapType.getRawClass(), null);
return null;
}
}
@Deprecated // since 2.5
protected void wrapAndThrow(Throwable t, Object ref) throws IOException {
wrapAndThrow(t, ref, null);
}
private void handleUnresolvedReference(JsonParser jp, MapReferringAccumulator accumulator,
Object key, UnresolvedForwardReference reference)
throws JsonMappingException
{
if (accumulator == null) {
throw JsonMappingException.from(jp, "Unresolved forward reference but no identity info.", reference);
}
Referring referring = accumulator.handleUnresolvedReference(reference, key);
reference.getRoid().appendReferring(referring);
}
private final static class MapReferringAccumulator {
private final Class<?> _valueType;
private Map<Object,Object> _result;
/**
* A list of {@link MapReferring} to maintain ordering.
*/
private List<MapReferring> _accumulator = new ArrayList<MapReferring>();
public MapReferringAccumulator(Class<?> valueType, Map<Object, Object> result) {
_valueType = valueType;
_result = result;
}
public void put(Object key, Object value)
{
if (_accumulator.isEmpty()) {
_result.put(key, value);
} else {
Map
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> }
public int getAnnotationCount() { return 0; }
@Override
public int hashCode() {
return _name.hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
VirtualAnnotatedMember other = (VirtualAnnotatedMember) o;
return (other._declaringClass == _declaringClass)
&& other._name.equals(_name);
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
@SuppressWarnings("serial")
public class UnknownSerializer
extends StdSerializer<Object>
{
public UnknownSerializer() {
super(Object.class);
}
/**
* @since 2.6
*/
public UnknownSerializer(Class<?> cls) {
super(cls, false);
}
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
// 27-Nov-2009, tatu: As per [JACKSON-201] may or may not fail...
if (provider.isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)) {
failForEmpty(value);
}
// But if it's fine, we'll just output empty JSON Object:
gen.writeStartObject();
gen.writeEndObject();
}
@Override
public final void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
if (provider.isEnabled(SerializationFeature.FAIL_ON_EMPTY_BEANS)) {
failForEmpty(value);
}
typeSer.writeTypePrefixForObject(value, gen);
typeSer.writeTypeSuffixForObject(value, gen);
}
@Override
public boolean isEmpty(SerializerProvider provider, Object value) {
return true;
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
return null;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitor.expectAnyFormat(typeHint);
}
protected void failForEmpty(Object value) throws JsonMappingException
{
throw new JsonMappingException("No serializer found for class "+value.getClass().getName()+" and no properties discovered to
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> @Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// This method should never be called...
throw ctxt.instantiationException(_baseType.getRawClass(),
"abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information");
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected Object _deserializeIfNatural(JsonParser jp, DeserializationContext ctxt) throws IOException
{
/* As per [JACKSON-417], there is a chance we might be "natural" types
* (String, Boolean, Integer, Double), which do not include any type information...
* Care must be taken to only return this if return type matches, however.
* Finally, we may have to consider possibility of custom handlers for
* these values: but for now this should work ok.
*/
switch (jp.getCurrentTokenId()) {
case JsonTokenId.ID_STRING:
if (_acceptString) {
return jp.getText();
}
break;
case JsonTokenId.ID_NUMBER_INT:
if (_acceptInt) {
return jp.getIntValue();
}
break;
case JsonTokenId.ID_NUMBER_FLOAT:
if (_acceptDouble) {
return Double.valueOf(jp.getDoubleValue());
}
break;
case JsonTokenId.ID_TRUE:
if (_acceptBoolean) {
return Boolean.TRUE;
}
break;
case JsonTokenId.ID_FALSE:
if (_acceptBoolean) {
return Boolean.FALSE;
}
break;
}
return null;
}
/**
* Method called in cases where it looks like we got an Object Id
* to parse and use as a reference.
*/
protected Object _deserializeFromObjectId(JsonParser jp, DeserializationContext ctxt) throws IOException
{
Object id = _objectIdReader.readObjectReference(jp, ctxt);
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
// do we have it resolved?
Object pojo = roid.resolve();
if (pojo == null) { // not yet; should wait...
throw new UnresolvedForwardReference("Could not resolve Object Id
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>;
}
@Override
public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
AnnotatedMember am, JavaType baseType)
{
TypeResolverBuilder<?> b = _primary.findPropertyTypeResolver(config, am, baseType);
if (b == null) {
b = _secondary.findPropertyTypeResolver(config, am, baseType);
}
return b;
}
@Override
public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config,
AnnotatedMember am, JavaType baseType)
{
TypeResolverBuilder<?> b = _primary.findPropertyContentTypeResolver(config, am, baseType);
if (b == null) {
b = _secondary.findPropertyContentTypeResolver(config, am, baseType);
}
return b;
}
@Override
public List<NamedType> findSubtypes(Annotated a)
{
List<NamedType> types1 = _primary.findSubtypes(a);
List<NamedType> types2 = _secondary.findSubtypes(a);
if (types1 == null || types1.isEmpty()) return types2;
if (types2 == null || types2.isEmpty()) return types1;
ArrayList<NamedType> result = new ArrayList<NamedType>(types1.size() + types2.size());
result.addAll(types1);
result.addAll(types2);
return result;
}
@Override
public String findTypeName(AnnotatedClass ac)
{
String name = _primary.findTypeName(ac);
if (name == null || name.length() == 0) {
name = _secondary.findTypeName(ac);
}
return name;
}
// // // General member (field, method/constructor) annotations
@Override
public ReferenceProperty findReferenceType(AnnotatedMember member) {
ReferenceProperty r = _primary.findReferenceType(member);
return (r == null) ? _secondary.findReferenceType(member) : r;
}
@Override
public NameTransformer findUnwrappingNameTransformer(AnnotatedMember member) {
NameTransformer r = _primary.findUnwrappingNameTransformer(member);
return (r == null) ? _secondary.findUnwrappingNameTransformer(member) : r;
}
@Override
public Object findInjectableValueId
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> Class<?>[] result = _primary.findViews(a);
if (result == null) {
result = _secondary.findViews(a);
}
return result;
}
@Override
public Boolean isTypeId(AnnotatedMember member) {
Boolean b = _primary.isTypeId(member);
return (b == null) ? _secondary.isTypeId(member) : b;
}
@Override
public ObjectIdInfo findObjectIdInfo(Annotated ann) {
ObjectIdInfo r = _primary.findObjectIdInfo(ann);
return (r == null) ? _secondary.findObjectIdInfo(ann) : r;
}
@Override
public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) {
// to give precedence for primary, must start with secondary:
objectIdInfo = _secondary.findObjectReferenceInfo(ann, objectIdInfo);
objectIdInfo = _primary.findObjectReferenceInfo(ann, objectIdInfo);
return objectIdInfo;
}
@Override
public JsonFormat.Value findFormat(Annotated ann) {
JsonFormat.Value r = _primary.findFormat(ann);
return (r == null) ? _secondary.findFormat(ann) : r;
}
@Override
public PropertyName findWrapperName(Annotated ann) {
PropertyName name = _primary.findWrapperName(ann);
if (name == null) {
name = _secondary.findWrapperName(ann);
} else if (name == PropertyName.USE_DEFAULT) {
// does the other introspector have a better idea?
PropertyName name2 = _secondary.findWrapperName(ann);
if (name2 != null) {
name = name2;
}
}
return name;
}
@Override
public String findPropertyDefaultValue(Annotated ann) {
String str = _primary.findPropertyDefaultValue(ann);
return (str == null || str.isEmpty()) ? _secondary.findPropertyDefaultValue(ann) : str;
}
@Override
public String findPropertyDescription(Annotated ann) {
String r = _primary.findPropertyDescription(ann);
return (r == null) ? _secondary.findPropertyDescription(ann) : r;
}
@Override
public Integer findPropertyIndex(Annotated ann) {
Integer r = _
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> _typeParameters.length) {
return null;
}
return _typeParameters[index];
}
@Override
public String containedTypeName(int index)
{
if (index < 0 || _typeNames == null || index >= _typeNames.length) {
return null;
}
return _typeNames[index];
}
@Override
public Class<?> getParameterSource() {
return _typeParametersFor;
}
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
return _classSignature(_class, sb, true);
}
@Override
public StringBuilder getGenericSignature(StringBuilder sb)
{
_classSignature(_class, sb, false);
if (_typeParameters != null) {
sb.append('<');
for (JavaType param : _typeParameters) {
sb = param.getGenericSignature(sb);
}
sb.append('>');
}
sb.append(';');
return sb;
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(40);
sb.append("[simple type, class ").append(buildCanonicalName()).append(']');
return sb.toString();
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
SimpleType other = (SimpleType) o;
// Classes must be identical...
if (other._class != this._class) return false;
// And finally, generic bindings, if any
JavaType[] p1 = _typeParameters;
JavaType[] p2 = other._typeParameters;
if (p1 == null) {
return (p2 == null) || p2.length == 0;
}
if (p2 == null) return false;
if (p1.length != p2.length) return false;
for (int i = 0, len = p1.length; i < len; ++i) {
if (!p1[i].equals(p2[i])) {
return false;
}
}
return true;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> required, apply wrapper name: note, MUST be done after
* annotations are merged.
*/
if (_config.isEnabled(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)) {
_renameWithWrappers(props);
}
// well, almost last: there's still ordering...
_sortProperties(props);
_properties = props;
_collected = true;
}
/*
/**********************************************************
/* Overridable internal methods, adding members
/**********************************************************
*/
/**
* Method for collecting basic information on all fields found
*/
protected void _addFields(Map<String, POJOPropertyBuilder> props)
{
final AnnotationIntrospector ai = _annotationIntrospector;
/* 28-Mar-2013, tatu: For deserialization we may also want to remove
* final fields, as often they won't make very good mutators...
* (although, maybe surprisingly, JVM _can_ force setting of such fields!)
*/
final boolean pruneFinalFields = !_forSerialization && !_config.isEnabled(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);
final boolean transientAsIgnoral = _config.isEnabled(MapperFeature.PROPAGATE_TRANSIENT_MARKER);
for (AnnotatedField f : _classDef.fields()) {
String implName = (ai == null) ? null : ai.findImplicitPropertyName(f);
if (implName == null) {
implName = f.getName();
}
PropertyName pn;
if (ai == null) {
pn = null;
} else if (_forSerialization) {
/* 18-Aug-2011, tatu: As per existing unit tests, we should only
* use serialization annotation (@JsonSerializer) when serializing
* fields, and similarly for deserialize-only annotations... so
* no fallbacks in this particular case.
*/
pn = ai.findNameForSerialization(f);
} else {
pn = ai.findNameForDeserialization(f);
}
boolean nameExplicit = (pn != null);
if (nameExplicit && pn.isEmpty()) { // empty String meaning "use default name", here just means "same as field name"
pn = _propNameFromSimple(implName);
name
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>2.4
*/
protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
AnnotatedParameter param)
{
// JDK 8, paranamer, Scala can give implicit name
String impl = _annotationIntrospector.findImplicitPropertyName(param);
if (impl == null) {
impl = "";
}
PropertyName pn = _annotationIntrospector.findNameForDeserialization(param);
boolean expl = (pn != null && !pn.isEmpty());
if (!expl) {
if (impl.isEmpty()) {
/* Important: if neither implicit nor explicit name, can not make use
* of this creator parameter -- may or may not be a problem, verified
* at a later point.
*/
return;
}
// Also: if this occurs, there MUST be explicit annotation on creator itself
if (!_annotationIntrospector.hasCreatorAnnotation(param.getOwner())) {
return;
}
pn = PropertyName.construct(impl);
}
// shouldn't need to worry about @JsonIgnore, since creators only added
// if so annotated
/* 13-May-2015, tatu: We should try to start with implicit name, similar to how
* fields and methods work; but unlike those, we don't necessarily have
* implicit name to use (pre-Java8 at least). So:
*/
POJOPropertyBuilder prop = (expl && impl.isEmpty())
? _property(props, pn) : _property(props, impl);
prop.addCtor(param, pn, expl, true, false);
_creatorProperties.add(prop);
}
/**
* Method for collecting basic information on all fields found
*/
protected void _addMethods(Map<String, POJOPropertyBuilder> props)
{
final AnnotationIntrospector ai = _annotationIntrospector;
for (AnnotatedMethod m : _classDef.memberMethods()) {
/* For methods, handling differs between getters and setters; and
* we will also only consider entries that either follow the bean
* naming convention or are explicitly marked: just being visible
* is not enough (unlike with fields)
*/
int argCount = m.getParameterCount();
if (argCount == 0) { // getters (including 'any getter')
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> explicit indication of inclusion, but may be empty
// we still need implicit name to link with other pieces
implName = (ai == null) ? null : ai.findImplicitPropertyName(m);
if (implName == null) {
implName = BeanUtil.okNameForGetter(m, _stdBeanNaming);
}
// if not regular getter name, use method name as is
if (implName == null) {
implName = m.getName();
}
if (pn.isEmpty()) {
// !!! TODO: use PropertyName for implicit names too
pn = _propNameFromSimple(implName);
nameExplicit = false;
}
visible = true;
}
boolean ignore = (ai == null) ? false : ai.hasIgnoreMarker(m);
_property(props, implName).addGetter(m, pn, nameExplicit, visible, ignore);
}
protected void _addSetterMethod(Map<String, POJOPropertyBuilder> props,
AnnotatedMethod m, AnnotationIntrospector ai)
{
String implName; // from naming convention
boolean visible;
PropertyName pn = (ai == null) ? null : ai.findNameForDeserialization(m);
boolean nameExplicit = (pn != null);
if (!nameExplicit) { // no explicit name; must follow naming convention
implName = (ai == null) ? null : ai.findImplicitPropertyName(m);
if (implName == null) {
implName = BeanUtil.okNameForMutator(m, _mutatorPrefix, _stdBeanNaming);
}
if (implName == null) { // if not, must skip
return;
}
visible = _visibilityChecker.isSetterVisible(m);
} else { // explicit indication of inclusion, but may be empty
// we still need implicit name to link with other pieces
implName = (ai == null) ? null : ai.findImplicitPropertyName(m);
if (implName == null) {
implName = BeanUtil.okNameForMutator(m, _mutatorPrefix, _stdBeanNaming);
}
// if not regular getter name, use method name as is
if (implName == null) {
implName = m.getName();
}
if (pn.isEmpty()) {
// !!! TODO: use PropertyName
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> for implicit names too
pn = _propNameFromSimple(implName);
nameExplicit = false;
}
visible = true;
}
boolean ignore = (ai == null) ? false : ai.hasIgnoreMarker(m);
_property(props, implName).addSetter(m, pn, nameExplicit, visible, ignore);
}
protected void _addInjectables(Map<String, POJOPropertyBuilder> props)
{
final AnnotationIntrospector ai = _annotationIntrospector;
if (ai == null) {
return;
}
// first fields, then methods
for (AnnotatedField f : _classDef.fields()) {
_doAddInjectable(ai.findInjectableValueId(f), f);
}
for (AnnotatedMethod m : _classDef.memberMethods()) {
/* for now, only allow injection of a single arg
* (to be changed in future)
*/
if (m.getParameterCount() != 1) {
continue;
}
_doAddInjectable(ai.findInjectableValueId(m), m);
}
}
protected void _doAddInjectable(Object id, AnnotatedMember m)
{
if (id == null) {
return;
}
if (_injectables == null) {
_injectables = new LinkedHashMap<Object, AnnotatedMember>();
}
AnnotatedMember prev = _injectables.put(id, m);
if (prev != null) {
String type = id.getClass().getName();
throw new IllegalArgumentException("Duplicate injectable value with id '"
+String.valueOf(id)+"' (of type "+type+")");
}
}
private PropertyName _propNameFromSimple(String simpleName) {
return PropertyName.construct(simpleName, null);
}
/*
/**********************************************************
/* Internal methods; removing ignored properties
/**********************************************************
*/
/**
* Method called to get rid of candidate properties that are marked
* as ignored.
*/
protected void _removeUnwantedProperties(Map<String, POJOPropertyBuilder> props)
{
Iterator<POJOPropertyBuilder> it = props.values().iterator();
while (it.hasNext()) {
POJOPropertyBuilder prop = it.next();
// First: if nothing visible, just remove altogether
if (!prop.any
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> is fine as is
if (l.isEmpty()) {
continue;
}
it.remove(); // need to replace with one or more renamed
if (renamed == null) {
renamed = new LinkedList<POJOPropertyBuilder>();
}
// simple renaming? Just do it
if (l.size() == 1) {
PropertyName n = l.iterator().next();
renamed.add(prop.withName(n));
continue;
}
// but this may be problematic...
renamed.addAll(prop.explode(l));
/*
String newName = prop.findNewName();
if (newName != null) {
if (renamed == null) {
renamed = new LinkedList<POJOPropertyBuilder>();
}
prop = prop.withSimpleName(newName);
renamed.add(prop);
it.remove();
}
*/
}
// and if any were renamed, merge back in...
if (renamed != null) {
for (POJOPropertyBuilder prop : renamed) {
String name = prop.getName();
POJOPropertyBuilder old = props.get(name);
if (old == null) {
props.put(name, prop);
} else {
old.addAll(prop);
}
// replace the creatorProperty too, if there is one
_updateCreatorProperty(prop, _creatorProperties);
}
}
}
protected void _renameUsing(Map<String, POJOPropertyBuilder> propMap,
PropertyNamingStrategy naming)
{
POJOPropertyBuilder[] props = propMap.values().toArray(new POJOPropertyBuilder[propMap.size()]);
propMap.clear();
for (POJOPropertyBuilder prop : props) {
PropertyName fullName = prop.getFullName();
String rename = null;
// As per [#428](https://github.com/FasterXML/jackson-databind/issues/428) need
// to skip renaming if property has explicitly defined name
if (!prop.isExplicitlyNamed()) {
if (_forSerialization) {
if (prop.hasGetter()) {
rename = naming.nameForGetterMethod(_config, prop.getGetter(), fullName.getSimpleName());
} else if (prop.hasField()) {
rename = naming.nameForField(_config, prop.getField(),
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> _annotationIntrospector.findWrapperName(member);
// One trickier part (wrt [Issue#24] of JAXB annotations: wrapper that
// indicates use of actual property... But hopefully has been taken care
// of previously
if (wrapperName == null || !wrapperName.hasSimpleName()) {
continue;
}
if (!wrapperName.equals(prop.getFullName())) {
if (renamed == null) {
renamed = new LinkedList<POJOPropertyBuilder>();
}
prop = prop.withName(wrapperName);
renamed.add(prop);
it.remove();
}
}
// and if any were renamed, merge back in...
if (renamed != null) {
for (POJOPropertyBuilder prop : renamed) {
String name = prop.getName();
POJOPropertyBuilder old = props.get(name);
if (old == null) {
props.put(name, prop);
} else {
old.addAll(prop);
}
}
}
}
/*
/**********************************************************
/* Overridable internal methods, sorting, other stuff
/**********************************************************
*/
/* First, order by [JACKSON-90] (explicit ordering and/or alphabetic)
* and then for [JACKSON-170] (implicitly order creator properties before others)
*/
protected void _sortProperties(Map<String, POJOPropertyBuilder> props)
{
// Then how about explicit ordering?
AnnotationIntrospector intr = _annotationIntrospector;
boolean sort;
Boolean alpha = (intr == null) ? null : intr.findSerializationSortAlphabetically((Annotated) _classDef);
if (alpha == null) {
sort = _config.shouldSortPropertiesAlphabetically();
} else {
sort = alpha.booleanValue();
}
String[] propertyOrder = (intr == null) ? null : intr.findSerializationPropertyOrder(_classDef);
// no sorting? no need to shuffle, then
if (!sort && (_creatorProperties == null) && (propertyOrder == null)) {
return;
}
int size = props.size();
Map<String, POJOPropertyBuilder> all;
// Need to (re)sort alphabetically?
if (sort) {
all = new TreeMap<String,POJO
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>PropertyBuilder>();
} else {
all = new LinkedHashMap<String,POJOPropertyBuilder>(size+size);
}
for (POJOPropertyBuilder prop : props.values()) {
all.put(prop.getName(), prop);
}
Map<String,POJOPropertyBuilder> ordered = new LinkedHashMap<String,POJOPropertyBuilder>(size+size);
// Ok: primarily by explicit order
if (propertyOrder != null) {
for (String name : propertyOrder) {
POJOPropertyBuilder w = all.get(name);
if (w == null) { // also, as per [JACKSON-268], we will allow use of "implicit" names
for (POJOPropertyBuilder prop : props.values()) {
if (name.equals(prop.getInternalName())) {
w = prop;
// plus re-map to external name, to avoid dups:
name = prop.getName();
break;
}
}
}
if (w != null) {
ordered.put(name, w);
}
}
}
// And secondly by sorting Creator properties before other unordered properties
if (_creatorProperties != null) {
/* As per [Issue#311], this is bit delicate; but if alphabetic ordering
* is mandated, at least ensure creator properties are in alphabetic
* order. Related question of creator vs non-creator is punted for now,
* so creator properties still fully predate non-creator ones.
*/
Collection<POJOPropertyBuilder> cr;
if (sort) {
TreeMap<String, POJOPropertyBuilder> sorted =
new TreeMap<String,POJOPropertyBuilder>();
for (POJOPropertyBuilder prop : _creatorProperties) {
sorted.put(prop.getName(), prop);
}
cr = sorted.values();
} else {
cr = _creatorProperties;
}
for (POJOPropertyBuilder prop : cr) {
ordered.put(prop.getName(), prop);
}
}
// And finally whatever is left (trying to put again will not change ordering)
ordered.putAll(all);
props.clear();
props.putAll(ordered);
}
/*
/**********************************************************
/* Internal methods; helpers
/**********************************************************
*/
protected void reportProblem
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Properties) {
if (creatorProperties != null) {
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
if (creatorProperties.get(i).getInternalName().equals(prop.getInternalName())) {
creatorProperties.set(i, prop);
break;
}
}
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> {
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
if (_elementType != null) {
sb.append('<');
sb.append(_elementType.toCanonical());
sb.append('>');
}
return sb.toString();
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method that can be used for checking whether this type is a
* "real" Collection type; meaning whether it represents a parameterized
* subtype of {@link java.util.Collection} or just something that acts
* like one.
*/
public boolean isTrueCollectionType() {
return Collection.class.isAssignableFrom(_class);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
CollectionLikeType other = (CollectionLikeType) o;
return (_class == other._class) && _elementType.equals(other._elementType);
}
@Override
public String toString()
{
return "[collection-like type; class "+_class.getName()+", contains "+_elementType+"]";
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> IllegalStateException("Should not be called on this type");
}
/*
/**********************************************************
/* Overrides for actual serialization, value access
/**********************************************************
*/
@Override
protected Object value(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception {
return prov.getAttribute(_attrName);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>**********************************************************
*/
/**
* Low-level lookup method moved from {@link com.fasterxml.jackson.databind.util.ClassUtil},
* to allow for overriding of lookup functionality in environments like OSGi.
*
* @since 2.6
*/
public Class<?> findClass(String className) throws ClassNotFoundException
{
if (className.indexOf('.') < 0) {
Class<?> prim = _findPrimitive(className);
if (prim != null) {
return prim;
}
}
// Two-phase lookup: first using context ClassLoader; then default
Throwable prob = null;
ClassLoader loader = this.getClassLoader();
if (loader == null) {
loader = Thread.currentThread().getContextClassLoader();
}
if (loader != null) {
try {
return classForName(className, true, loader);
} catch (Exception e) {
prob = ClassUtil.getRootCause(e);
}
}
try {
return classForName(className);
} catch (Exception e) {
if (prob == null) {
prob = ClassUtil.getRootCause(e);
}
}
if (prob instanceof RuntimeException) {
throw (RuntimeException) prob;
}
throw new ClassNotFoundException(prob.getMessage(), prob);
}
protected Class<?> classForName(String name, boolean initialize,
ClassLoader loader) throws ClassNotFoundException {
return Class.forName(name, true, loader);
}
protected Class<?> classForName(String name) throws ClassNotFoundException {
return Class.forName(name);
}
protected Class<?> _findPrimitive(String className)
{
if ("int".equals(className)) return Integer.TYPE;
if ("long".equals(className)) return Long.TYPE;
if ("float".equals(className)) return Float.TYPE;
if ("double".equals(className)) return Double.TYPE;
if ("boolean".equals(className)) return Boolean.TYPE;
if ("byte".equals(className)) return Byte.TYPE;
if ("char".equals(className)) return Character.TYPE;
if ("short".equals(className)) return Short.TYPE;
if ("void".equals(className)) return Void.TYPE;
return null;
}
/*
/**********************************************************
/* Type conversion, parameterization resolution methods
/**********************************************************
*/
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Params[0]);
}
protected JavaType _resolveVariableViaSubTypes(HierarchicType leafType, String variableName, TypeBindings bindings)
{
// can't resolve raw types; possible to have as-of-yet-unbound types too:
if (leafType != null && leafType.isGeneric()) {
TypeVariable<?>[] typeVariables = leafType.getRawClass().getTypeParameters();
for (int i = 0, len = typeVariables.length; i < len; ++i) {
TypeVariable<?> tv = typeVariables[i];
if (variableName.equals(tv.getName())) {
// further resolution needed?
Type type = leafType.asGeneric().getActualTypeArguments()[i];
if (type instanceof TypeVariable<?>) {
return _resolveVariableViaSubTypes(leafType.getSubType(), ((TypeVariable<?>) type).getName(), bindings);
}
// no we're good for the variable (but it may have parameterization of its own)
return _constructType(type, bindings);
}
}
}
return _unknownType();
}
protected JavaType _unknownType() {
return new SimpleType(Object.class);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* Helper method used to find inheritance (implements, extends) path
* between given types, if one exists (caller generally checks before
* calling this method). Returned type represents given <b>subtype</b>,
* with supertype linkage extending to <b>supertype</b>.
*/
protected HierarchicType _findSuperTypeChain(Class<?> subtype, Class<?> supertype)
{
// If super-type is a class (not interface), bit simpler
if (supertype.isInterface()) {
return _findSuperInterfaceChain(subtype, supertype);
}
return _findSuperClassChain(subtype, supertype);
}
protected HierarchicType _findSuperClassChain(Type currentType, Class<?> target)
{
HierarchicType current = new HierarchicType(currentType);
Class<?> raw = current.getRawClass();
if (raw == target) {
return current;
}
// Otherwise, keep on going down the rat hole...
Type parent = raw.getGenericSuperclass();
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.type.ClassKey;
/**
* Simple implementation of {@link ClassIntrospector.MixInResolver}
* that just uses a {@link java.util.Map} for containing mapping
* from target to mix-in classes.
*<p>
* Implementation is only thread-safe after initialization (that is,
* when underlying Map is not modified but only read).
*
* @since 2.6
*/
public class SimpleMixInResolver
implements ClassIntrospector.MixInResolver,
java.io.Serializable
{
private static final long serialVersionUID = 1L;
/**
* External resolver that gets called before looking at any locally defined
* mix-in target classes.
*/
protected final ClassIntrospector.MixInResolver _overrides;
/**
* Simple mix-in targets defined locally.
*/
protected Map<ClassKey,Class<?>> _localMixIns;
public SimpleMixInResolver(ClassIntrospector.MixInResolver overrides) {
_overrides = overrides;
}
protected SimpleMixInResolver(ClassIntrospector.MixInResolver overrides,
Map<ClassKey,Class<?>> mixins) {
_overrides = overrides;
_localMixIns = mixins;
}
/**
* Mutant factory for constructor a new resolver instance with given
* mix-in resolver override.
*/
public SimpleMixInResolver withOverrides(ClassIntrospector.MixInResolver overrides) {
return new SimpleMixInResolver(overrides, _localMixIns);
}
/**
* Mutant factory method that constructs a new instance that has no locally
* defined mix-in/target mappings.
*/
public SimpleMixInResolver withoutLocalDefinitions() {
return new SimpleMixInResolver(_overrides, null);
}
public void setLocalDefinitions(Map<Class<?>, Class<?>> sourceMixins) {
if (sourceMixins == null || sourceMixins.isEmpty()) {
_localMixIns = null;
}
Map<ClassKey,Class<?>> mixIns = new HashMap<ClassKey,Class<?>>(sourceMixins.size());
for (Map.Entry<Class<?>,Class<?>> en : sourceMixins
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
// At which point we still have all kinds of properties; not all with mutators:
for (BeanPropertyDefinition propDef : propDefs) {
SettableBeanProperty prop = null;
/* 18-Oct-2013, tatu: Although constructor parameters have highest precedence,
* we need to do linkage (as per [Issue#318]), and so need to start with
* other types, and only then create constructor parameter, if any.
*/
if (propDef.hasSetter()) {
Type propertyType = propDef.getSetter().getGenericParameterType(0);
prop = constructSettableProperty(ctxt, beanDesc, propDef, propertyType);
} else if (propDef.hasField()) {
Type propertyType = propDef.getField().getGenericType();
prop = constructSettableProperty(ctxt, beanDesc, propDef, propertyType);
} else if (useGettersAsSetters && propDef.hasGetter()) {
/* As per [JACKSON-88], may also need to consider getters
* for Map/Collection properties; but with lowest precedence
*/
AnnotatedMethod getter = propDef.getGetter();
// should only consider Collections and Maps, for now?
Class<?> rawPropertyType = getter.getRawType();
if (Collection.class.isAssignableFrom(rawPropertyType)
|| Map.class.isAssignableFrom(rawPropertyType)) {
prop = constructSetterlessProperty(ctxt, beanDesc, propDef);
}
}
// 25-Sep-2014, tatu: No point in finding constructor parameters for abstract types
// (since they are never used anyway)
if (isConcrete && propDef.hasConstructorParameter()) {
/* [JACKSON-700] If property is passed via constructor parameter, we must
* handle things in special way. Not sure what is the most optimal way...
* for now, let's just call a (new) method in builder, which does nothing.
*/
// but let's call a method just to allow custom builders to be aware...
final String name = propDef.getName();
CreatorProperty cprop = null;
if (creatorProps != null) {
for (SettableBeanProperty cp : creatorProps) {
if (name.equals(cp.getName()))
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser;
import com.fasterxml.jackson.databind.*;
/**
* Add-on interface that {@link JsonSerializer}s can implement to get a callback
* that can be used to create contextual instances of serializer to use for
* handling properties of supported type. This can be useful
* for serializers that can be configured by annotations, or should otherwise
* have differing behavior depending on what kind of property is being serialized.
*<p>
* Note that in cases where serializer needs both contextualization and
* resolution -- that is, implements both this interface and {@link ResolvableSerializer}
* -- resolution via {@link ResolvableSerializer} occurs first, and contextual
* resolution (via this interface) later on.
*/
public interface ContextualSerializer
{
/**
* Method called to see if a different (or differently configured) serializer
* is needed to serialize values of specified property.
* Note that instance that this method is called on is typically shared one and
* as a result method should <b>NOT</b> modify this instance but rather construct
* and return a new instance. This instance should only be returned as-is, in case
* it is already suitable for use.
*
* @param prov Serializer provider to use for accessing config, other serializers
* @param property Method or field that represents the property
* (and is used to access value to serialize).
* Should be available; but there may be cases where caller can not provide it and
* null is passed instead (in which case impls usually pass 'this' serializer as is)
*
* @return Serializer to use for serializing values of specified property;
* may be this instance or a new instance.
*
* @throws JsonMappingException
*/
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
throws JsonMappingException;
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Generic handler for types that implement {@link JsonSerializable}.
*<p>
* Note: given that this is used for anything that implements
* interface, can not be checked for direct class equivalence.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class SerializableSerializer
extends StdSerializer<JsonSerializable>
{
public final static SerializableSerializer instance = new SerializableSerializer();
// Ugh. Should NOT need this...
private final static AtomicReference<ObjectMapper> _mapperReference = new AtomicReference<ObjectMapper>();
protected SerializableSerializer() { super(JsonSerializable.class); }
@Override
public boolean isEmpty(SerializerProvider serializers, JsonSerializable value) {
if (value instanceof JsonSerializable.Base) {
return ((JsonSerializable.Base) value).isEmpty(serializers);
}
return false;
}
@Override
public void serialize(JsonSerializable value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
value.serialize(gen, serializers);
}
@Override
public final void serializeWithType(JsonSerializable value, JsonGenerator gen, SerializerProvider serializers,
TypeSerializer typeSer) throws IOException {
value.serializeWithType(gen, serializers, typeSer);
}
@Override
@SuppressWarnings("deprecation")
public JsonNode getSchema(Serializer
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Provider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode objectNode = createObjectNode();
String schemaType = "any";
String objectProperties = null;
String itemDefinition = null;
if (typeHint != null) {
Class<?> rawClass = TypeFactory.rawClass(typeHint);
if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) {
JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class);
schemaType = schemaInfo.schemaType();
if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) {
objectProperties = schemaInfo.schemaObjectPropertiesDefinition();
}
if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) {
itemDefinition = schemaInfo.schemaItemDefinition();
}
}
}
/* 19-Mar-2012, tatu: geez, this is butt-ugly abonimation of code...
* really, really should not require back ref to an ObjectMapper.
*/
objectNode.put("type", schemaType);
if (objectProperties != null) {
try {
objectNode.set("properties", _getObjectMapper().readTree(objectProperties));
} catch (IOException e) {
throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaObjectPropertiesDefinition value");
}
}
if (itemDefinition != null) {
try {
objectNode.set("items", _getObjectMapper().readTree(itemDefinition));
} catch (IOException e) {
throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaItemDefinition value");
}
}
// always optional, no need to specify:
//objectNode.put("required", false);
return objectNode;
}
private final static synchronized ObjectMapper _getObjectMapper()
{
ObjectMapper mapper = _mapperReference.get();
if (mapper == null) {
mapper = new ObjectMapper();
_mapperReference.set(mapper);
}
return mapper;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitor.expectAnyFormat(typeHint);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
/**
* Method needed to ensure that {@link ObjectMapper#copy} will work
* properly; specifically, that caches are cleared, but settings
* will otherwise remain identical; and that no sharing of state
* occurs.
*
* @since 2.5
*/
public DefaultSerializerProvider copy() {
throw new IllegalStateException("DefaultSerializerProvider sub-class not overriding copy()");
}
/*
/**********************************************************
/* Extended API: methods that ObjectMapper will call
/**********************************************************
*/
/**
* Overridable method, used to create a non-blueprint instances from the blueprint.
* This is needed to retain state during serialization.
*/
public abstract DefaultSerializerProvider createInstance(SerializationConfig config,
SerializerFactory jsf);
/**
* The method to be called by {@link ObjectMapper} and {@link ObjectWriter}
* for serializing given value, using serializers that
* this provider has access to (via caching and/or creating new serializers
* as need be).
*/
public void serializeValue(JsonGenerator gen, Object value) throws IOException
{
if (value == null) {
_serializeNull(gen);
return;
}
Class<?> cls = value.getClass();
// true, since we do want to cache root-level typed serializers (ditto for null property)
final JsonSerializer<Object> ser = findTypedValueSerializer(cls, true, null);
// Ok: should we wrap result in an additional property ("root name")?
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
if (rootName == null) { // not explicitly specified
// [JACKSON-163]
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else { // [JACKSON-764]
// empty String means explicitly disabled; non-empty that it is enabled
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
ser.serialize(value, gen, this);
if (
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // As per [JACKSON-99], pass IOException and subtypes as-is
throw ioe;
} catch (Exception e) { // but wrap RuntimeExceptions, to get path information
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(msg, e);
}
}
/**
* The method to be called by {@link ObjectMapper} and {@link ObjectWriter}
* for serializing given value (assumed to be of specified root type,
* instead of runtime type of value),
* using serializers that
* this provider has access to (via caching and/or creating new serializers
* as need be),
*
* @param rootType Type to use for locating serializer to use, instead of actual
* runtime type. Must be actual type, or one of its super types
*/
public void serializeValue(JsonGenerator gen, Object value, JavaType rootType) throws IOException
{
if (value == null) {
_serializeNull(gen);
return;
}
// Let's ensure types are compatible at this point
if (!rootType.getRawClass().isAssignableFrom(value.getClass())) {
_reportIncompatibleRootType(value, rootType);
}
// root value, not reached via property:
JsonSerializer<Object> ser = findTypedValueSerializer(rootType, true, null);
// Ok: should we wrap result in an additional property ("root name")?
final boolean wrap;
PropertyName rootName = _config.getFullRootName();
if (rootName == null) { // not explicitly specified
// [JACKSON-163]
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else { // [JACKSON-764]
// empty String means explicitly disabled; non-empty that it is enabled
wrap = true;
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Type);
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else { // [JACKSON-764]
// empty String means explicitly disabled; non-empty that it is enabled
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
ser.serialize(value, gen, this);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(msg, e);
}
}
/**
* Alternate serialization call used for polymorphic types, when {@link TypeSerializer}
* is already known, but the actual serializer may or may not be.
*
* @since 2.6
*/
public void serializePolymorphic(JsonGenerator gen, Object value, JavaType rootType,
JsonSerializer<Object> valueSer, TypeSerializer typeSer)
throws IOException
{
if (value == null) {
_serializeNull(gen);
return;
}
// Let's ensure types are compatible at this point
if ((rootType != null) && !rootType.getRawClass().isAssignableFrom(value.getClass())) {
_reportIncompatibleRootType(value, rootType);
}
/* 12-Jun-2015, tatu: nominal root type is necessary for Maps at least;
* possibly collections, but can cause problems for other polymorphic
* types. We really need to distinguish between serialization type,
* base type; but right we don't. Hence this check
*/
if (valueSer == null) {
if ((rootType != null) && rootType.isContainerType()) {
valueSer = findValueSerializer(rootType, null);
} else {
valueSer = findValueSerializer(value.getClass(), null);
}
}
final boolean wrap;
PropertyName rootName = _config.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>getFullRootName();
if (rootName == null) {
wrap = _config.isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
if (wrap) {
gen.writeStartObject();
PropertyName pname = _config.findRootName(value.getClass());
gen.writeFieldName(pname.simpleAsEncoded(_config));
}
} else if (rootName.isEmpty()) {
wrap = false;
} else {
wrap = true;
gen.writeStartObject();
gen.writeFieldName(rootName.getSimpleName());
}
try {
valueSer.serializeWithType(value, gen, this, typeSer);
if (wrap) {
gen.writeEndObject();
}
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(msg, e);
}
}
/**
* @deprecated since 2.6; remove from 2.7 or later
*/
@Deprecated
public void serializePolymorphic(JsonGenerator gen, Object value, TypeSerializer typeSer)
throws IOException
{
JavaType t = (value == null) ? null : _config.constructType(value.getClass());
serializePolymorphic(gen, value, t, null, typeSer);
}
/**
* Helper method called when root value to serialize is null
*
* @since 2.3
*/
protected void _serializeNull(JsonGenerator gen) throws IOException
{
JsonSerializer<Object> ser = getDefaultNullValueSerializer();
try {
ser.serialize(null, gen, this);
} catch (IOException ioe) { // no wrapping for IO (and derived)
throw ioe;
} catch (Exception e) { // but others do need to be, to get path etc
String msg = e.getMessage();
if (msg == null) {
msg = "[no message for "+e.getClass().getName()+"]";
}
throw new JsonMappingException(msg, e);
}
}
/**
* The method to be called by {@link ObjectMapper}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> we
* have enough information, or return null if not.
*/
public JsonSerializer<?> build()
{
BeanPropertyWriter[] properties;
// No properties, any getter or object id writer?
// No real serializer; caller gets to handle
if (_properties == null || _properties.isEmpty()) {
if (_anyGetter == null && _objectIdWriter == null) {
return null;
}
properties = NO_PROPERTIES;
} else {
properties = _properties.toArray(new BeanPropertyWriter[_properties.size()]);
}
return new BeanSerializer(_beanDesc.getType(), this,
properties, _filteredProperties);
}
/**
* Factory method for constructing an "empty" serializer; one that
* outputs no properties (but handles JSON objects properly, including
* type information)
*/
public BeanSerializer createDummy() {
return BeanSerializer.createDummy(_beanDesc.getType());
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> = format.getTimeZone();
if (format.hasPattern()) {
String pattern = format.getPattern();
final Locale loc = format.hasLocale() ? format.getLocale() : serializers.getLocale();
SimpleDateFormat df = new SimpleDateFormat(pattern, loc);
if (tz == null) {
tz = serializers.getTimeZone();
}
df.setTimeZone(tz);
return withFormat(asNumber, df);
}
// If not, do we at least have a custom timezone?
if (tz != null) {
DateFormat df = serializers.getConfig().getDateFormat();
// one shortcut: with our custom format, can simplify handling a bit
if (df.getClass() == StdDateFormat.class) {
final Locale loc = format.hasLocale() ? format.getLocale() : serializers.getLocale();
df = StdDateFormat.getISO8601Format(tz, loc);
} else {
// otherwise need to clone, re-set timezone:
df = (DateFormat) df.clone();
df.setTimeZone(tz);
}
return withFormat(asNumber, df);
}
}
}
return this;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Deprecated
@Override
public boolean isEmpty(T value) {
// let's assume "null date" (timestamp 0) qualifies for empty
return (value == null) || (_timestamp(value) == 0L);
}
@Override
public boolean isEmpty(SerializerProvider serializers, T value) {
// let's assume "null date" (timestamp 0) qualifies for empty
return (value == null) || (_timestamp(value) == 0L);
}
protected abstract long _timestamp(T value);
@Override
public JsonNode getSchema(SerializerProvider serializers, Type typeHint) {
//todo: (ryan) add a format for the date in the schema?
return createSchemaNode(_asTimestamp(serializers) ? "number" : "string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
_acceptJsonFormatVisitor(visitor, typeHint, _asTimestamp(visitor.getProvider()));
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> true,
* this method may return null .
*/
public AnnotatedWithParams getWithArgsCreator() { return null; }
/**
* If an incomplete creator was found, this is the first parameter that
* needs further annotation to help make the creator complete.
*/
public AnnotatedParameter getIncompleteParameter() { return null; }
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* @since 2.4 (demoted from <code>StdValueInstantiator</code>)
*/
protected Object _createFromStringFallbacks(DeserializationContext ctxt, String value)
throws IOException, JsonProcessingException
{
/* 28-Sep-2011, tatu: Ok this is not clean at all; but since there are legacy
* systems that expect conversions in some cases, let's just add a minimal
* patch (note: same could conceivably be used for numbers too).
*/
if (canCreateFromBoolean()) {
String str = value.trim();
if ("true".equals(str)) {
return createFromBoolean(ctxt, true);
}
if ("false".equals(str)) {
return createFromBoolean(ctxt, false);
}
}
// also, empty Strings might be accepted as null Object...
if (value.length() == 0) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
return null;
}
}
throw ctxt.mappingException("Can not instantiate value of type "+getValueTypeDesc()
+" from String value ('"+value+"'); no single-String constructor/factory method");
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.text.DateFormat;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
/**
* For efficiency, we will serialize Dates as longs, instead of
* potentially more readable Strings.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class DateSerializer
extends DateTimeSerializerBase<Date>
{
/**
* Default instance that is used when no contextual configuration
* is needed.
*/
public static final DateSerializer instance = new DateSerializer();
public DateSerializer() {
this(null, null);
}
public DateSerializer(Boolean useTimestamp, DateFormat customFormat) {
super(Date.class, useTimestamp, customFormat);
}
@Override
public DateSerializer withFormat(Boolean timestamp, DateFormat customFormat) {
return new DateSerializer(timestamp, customFormat);
}
@Override
protected long _timestamp(Date value) {
return (value == null) ? 0L : value.getTime();
}
@Override
public void serialize(Date value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
if (_asTimestamp(provider)) {
gen.writeNumber(_timestamp(value));
} else if (_customFormat != null) {
// 21-Feb-2011, tatu: not optimal, but better than alternatives:
synchronized (_customFormat) {
gen.writeString(_customFormat.format(value));
}
} else {
provider.defaultSerializeDateValue(value, gen);
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
@Override
public int getParameterCount() {
return getRawParameterTypes().length;
}
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName() + "("
+getParameterCount()+" params)";
}
public Class<?>[] getRawParameterTypes()
{
if (_paramClasses == null) {
_paramClasses = _method.getParameterTypes();
}
return _paramClasses;
}
public Type[] getGenericParameterTypes() {
return _method.getGenericParameterTypes();
}
@Override
public Class<?> getRawParameterType(int index)
{
Class<?>[] types = getRawParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public Type getGenericParameterType(int index)
{
Type[] types = _method.getGenericParameterTypes();
return (index >= types.length) ? null : types[index];
}
public Class<?> getRawReturnType() {
return _method.getReturnType();
}
public Type getGenericReturnType() {
return _method.getGenericReturnType();
}
/**
* Helper method that can be used to check whether method returns
* a value or not; if return type declared as <code>void</code>, returns
* false, otherwise true
*
* @since 2.4
*/
public boolean hasReturnType() {
Class<?> rt = getRawReturnType();
return (rt != Void.TYPE && rt != Void.class);
}
/*
/********************************************************
/* Other
/********************************************************
*/
@Override
public String toString() {
return "[method "+getFullName()+"]";
}
@Override
public int hashCode() {
return _method.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedMethod) o)._method == _method;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedMethod(new Serialization(_method));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Method m = clazz.getDeclaredMethod(_serialization.name
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> * @param bigDecimalExact see description
*
* @see BigDecimal
*/
public JsonNodeFactory(boolean bigDecimalExact)
{
_cfgBigDecimalExact = bigDecimalExact;
}
/**
* Default constructor
*
* <p>This calls {@link #JsonNodeFactory(boolean)} with {@code false}
* as an argument.</p>
*/
protected JsonNodeFactory()
{
this(false);
}
/**
* Return a factory instance with the desired behavior for BigDecimals
* <p>See {@link #JsonNodeFactory(boolean)} for a full description.</p>
*
* @param bigDecimalExact see description
* @return a factory instance
*/
public static JsonNodeFactory withExactBigDecimals(boolean bigDecimalExact)
{
return bigDecimalExact ? decimalsAsIs : decimalsNormalized;
}
/*
/**********************************************************
/* Factory methods for literal values
/**********************************************************
*/
/**
* Factory method for getting an instance of JSON boolean value
* (either literal 'true' or 'false')
*/
@Override
public BooleanNode booleanNode(boolean v) {
return v ? BooleanNode.getTrue() : BooleanNode.getFalse();
}
/**
* Factory method for getting an instance of JSON null node (which
* represents literal null value)
*/
@Override
public NullNode nullNode() { return NullNode.getInstance(); }
/*
/**********************************************************
/* Factory methods for numeric values
/**********************************************************
*/
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given 8-bit value
*/
@Override
public NumericNode numberNode(byte v) { return IntNode.valueOf(v); }
/**
* Alternate factory method that will handle wrapper value, which may
* be null.
* Due to possibility of null, returning type is not guaranteed to be
* {@link NumericNode}, but just {@link ValueNode}.
*/
@Override
public ValueNode numberNode(Byte value) {
return (value == null) ? nullNode() : IntNode.valueOf(value.intValue());
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given 16-bit integer value
*/
@Override
public NumericNode numberNode(short v) { return ShortNode.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>valueOf(v); }
/**
* Alternate factory method that will handle wrapper value, which may
* be null.
* Due to possibility of null, returning type is not guaranteed to be
* {@link NumericNode}, but just {@link ValueNode}.
*/
@Override
public ValueNode numberNode(Short value) {
return (value == null) ? nullNode() : ShortNode.valueOf(value);
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given 32-bit integer value
*/
@Override
public NumericNode numberNode(int v) { return IntNode.valueOf(v); }
/**
* Alternate factory method that will handle wrapper value, which may
* be null.
* Due to possibility of null, returning type is not guaranteed to be
* {@link NumericNode}, but just {@link ValueNode}.
*/
@Override
public ValueNode numberNode(Integer value) {
return (value == null) ? nullNode() : IntNode.valueOf(value.intValue());
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given 64-bit integer value
*/
@Override
public NumericNode numberNode(long v) {
return LongNode.valueOf(v);
}
/**
* Alternate factory method that will handle wrapper value, which may be null.
* Due to possibility of null, returning type is not guaranteed to be
* {@link NumericNode}, but just {@link ValueNode}.
*/
@Override
public ValueNode numberNode(Long value) {
if (value == null) {
return nullNode();
}
return LongNode.valueOf(value.longValue());
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given unlimited range integer value
*/
@Override
public NumericNode numberNode(BigInteger v) { return BigIntegerNode.valueOf(v); }
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given 32-bit floating point value
*/
@Override
public NumericNode numberNode(float v) { return FloatNode.valueOf((float) v); }
/**
* Alternate factory method that will handle wrapper value, which may
* be null.
* Due to
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> possibility of null, returning type is not guaranteed to be
* {@link NumericNode}, but just {@link ValueNode}.
*/
@Override
public ValueNode numberNode(Float value) {
return (value == null) ? nullNode() : FloatNode.valueOf(value.floatValue());
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given 64-bit floating point value
*/
@Override
public NumericNode numberNode(double v) { return DoubleNode.valueOf(v); }
/**
* Alternate factory method that will handle wrapper value, which may
* be null.
* Due to possibility of null, returning type is not guaranteed to be
* {@link NumericNode}, but just {@link ValueNode}.
*/
@Override
public ValueNode numberNode(Double value) {
return (value == null) ? nullNode() : DoubleNode.valueOf(value.doubleValue());
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given unlimited precision floating point value
*
* <p>In the event that the factory has been built to normalize decimal
* values, the BigDecimal argument will be stripped off its trailing zeroes,
* using {@link BigDecimal#stripTrailingZeros()}.</p>
*
* @see #JsonNodeFactory(boolean)
*/
@Override
public NumericNode numberNode(BigDecimal v)
{
/*
* If the user wants the exact representation of this big decimal,
* return the value directly
*/
if (_cfgBigDecimalExact)
return DecimalNode.valueOf(v);
/*
* If the user has asked to strip trailing zeroes, however, there is
* this bug to account for:
*
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539
*
* In short: zeroes are never stripped out of 0! We therefore _have_
* to compare with BigDecimal.ZERO...
*/
return v.compareTo(BigDecimal.ZERO) == 0 ? DecimalNode.ZERO
: DecimalNode.valueOf(v.stripTrailingZeros());
}
/*
/**********************************************************
/* Factory methods for textual values
/**********************************************************
*/
/**
* Factory method for constructing a node that
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> represents JSON
* String value
*/
@Override
public TextNode textNode(String text) { return TextNode.valueOf(text); }
/**
* Factory method for constructing a node that represents given
* binary data, and will get serialized as equivalent base64-encoded
* String value
*/
@Override
public BinaryNode binaryNode(byte[] data) { return BinaryNode.valueOf(data); }
/**
* Factory method for constructing a node that represents given
* binary data, and will get serialized as equivalent base64-encoded
* String value
*/
@Override
public BinaryNode binaryNode(byte[] data, int offset, int length) {
return BinaryNode.valueOf(data, offset, length);
}
/*
/**********************************************************
/* Factory method for structured values
/**********************************************************
*/
/**
* Factory method for constructing an empty JSON Array node
*/
@Override
public ArrayNode arrayNode() { return new ArrayNode(this); }
/**
* Factory method for constructing an empty JSON Object ("struct") node
*/
@Override
public ObjectNode objectNode() { return new ObjectNode(this); }
/**
* Factory method for constructing a wrapper for POJO
* ("Plain Old Java Object") objects; these will get serialized
* using data binding, usually as JSON Objects, but in some
* cases as JSON Strings or other node types.
*/
@Override
public ValueNode pojoNode(Object pojo) { return new POJONode(pojo); }
@Override
public ValueNode rawValueNode(RawValue value) {
return new POJONode(value);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected boolean _inIntRange(long l)
{
int i = (int) l;
long l2 = (long) i;
return (l2 == l);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
*/
@Override
public final SerializerFactory withAdditionalSerializers(Serializers additional) {
return withConfig(_factoryConfig.withAdditionalSerializers(additional));
}
/**
* Convenience method for creating a new factory instance with an additional
* key serializer provider.
*/
@Override
public final SerializerFactory withAdditionalKeySerializers(Serializers additional) {
return withConfig(_factoryConfig.withAdditionalKeySerializers(additional));
}
/**
* Convenience method for creating a new factory instance with additional bean
* serializer modifier.
*/
@Override
public final SerializerFactory withSerializerModifier(BeanSerializerModifier modifier) {
return withConfig(_factoryConfig.withSerializerModifier(modifier));
}
/*
/**********************************************************
/* SerializerFactory impl
/**********************************************************
*/
// Implemented by sub-classes
@Override
public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov,
JavaType type)
throws JsonMappingException;
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<Object> createKeySerializer(SerializationConfig config,
JavaType keyType, JsonSerializer<Object> defaultImpl)
{
// We should not need any member method info; at most class annotations for Map type
// ... at least, not here.
BeanDescription beanDesc = config.introspectClassAnnotations(keyType.getRawClass());
JsonSerializer<?> ser = null;
// Minor optimization: to avoid constructing beanDesc, bail out if none registered
if (_factoryConfig.hasKeySerializers()) {
// Only thing we have here are module-provided key serializers:
for (Serializers serializers : _factoryConfig.keySerializers()) {
ser = serializers.findSerializer(config, keyType, beanDesc);
if (ser != null) {
break;
}
}
}
if (ser == null) {
ser = defaultImpl;
if (ser == null) {
ser = StdKeySerializers.getStdKeySerializer(config, keyType.getRawClass(), false);
// As per [databind#47], also need to support @JsonValue
if (ser == null) {
beanDesc = config.introspect(keyType);
AnnotatedMethod am = beanDesc.findJsonValueMethod();
if (am != null) {
final Class<?> rawType = am.getRawReturnType();
JsonSerializer<?> delegate = StdKeySerial
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>and identity comparison) methods to
* see if we know serializer to use for given type.
*/
protected final JsonSerializer<?> findSerializerByLookup(JavaType type,
SerializationConfig config, BeanDescription beanDesc,
boolean staticTyping)
{
Class<?> raw = type.getRawClass();
String clsName = raw.getName();
if (type.isReferenceType()) {
if (type.isTypeOrSubTypeOf(AtomicReference.class)) {
return new AtomicReferenceSerializer((ReferenceType) type);
}
}
JsonSerializer<?> ser = _concrete.get(clsName);
if (ser == null) {
Class<? extends JsonSerializer<?>> serClass = _concreteLazy.get(clsName);
if (serClass != null) {
try {
return serClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate standard serializer (of type "+serClass.getName()+"): "
+e.getMessage(), e);
}
}
}
return ser;
}
/**
* Method called to see if one of primary per-class annotations
* (or related, like implementing of {@link JsonSerializable})
* determines the serializer to use.
*<p>
* Currently handles things like:
*<ul>
* <li>If type implements {@link JsonSerializable}, use that
* </li>
* <li>If type has {@link com.fasterxml.jackson.annotation.JsonValue} annotation (or equivalent), build serializer
* based on that property
* </li>
*</ul>
*
* @since 2.0
*/
protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider prov,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
Class<?> raw = type.getRawClass();
// First: JsonSerializable?
if (JsonSerializable.class.isAssignableFrom(raw)) {
return SerializableSerializer.instance;
}
// Second: @JsonValue for any type
AnnotatedMethod valueMethod = beanDesc.findJsonValueMethod();
if (valueMethod != null) {
Method m = valueMethod.getAnnotated();
if (prov.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(m);
}
JsonSerializer<Object> ser = findSerializerFromAnnotation(prov, valueMethod);
return new
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> JsonValueSerializer(m, ser);
}
// No well-known annotations...
return null;
}
/**
* Method for checking if we can determine serializer to use based on set of
* known primary types, checking for set of known base types (exact matches
* having been compared against with <code>findSerializerByLookup</code>).
* This does not include "secondary" interfaces, but
* mostly concrete or abstract base classes.
*/
protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider prov,
JavaType type, BeanDescription beanDesc,
boolean staticTyping)
throws JsonMappingException
{
Class<?> raw = type.getRawClass();
// Then check for optional/external serializers [JACKSON-386]
JsonSerializer<?> ser = findOptionalStdSerializer(prov, type, beanDesc, staticTyping);
if (ser != null) {
return ser;
}
if (Calendar.class.isAssignableFrom(raw)) {
return CalendarSerializer.instance;
}
if (java.util.Date.class.isAssignableFrom(raw)) {
return DateSerializer.instance;
}
if (Map.Entry.class.isAssignableFrom(raw)) {
// 28-Apr-2015, tatu: TypeFactory does it all for us already so
JavaType kt = type.containedType(0);
if (kt == null) {
kt = TypeFactory.unknownType();
}
JavaType vt = type.containedType(1);
if (vt == null) {
vt = TypeFactory.unknownType();
}
return buildMapEntrySerializer(prov.getConfig(), type, beanDesc, staticTyping, kt, vt);
}
if (ByteBuffer.class.isAssignableFrom(raw)) {
return new ByteBufferSerializer();
}
if (InetAddress.class.isAssignableFrom(raw)) {
return new InetAddressSerializer();
}
if (InetSocketAddress.class.isAssignableFrom(raw)) {
return new InetSocketAddressSerializer();
}
if (TimeZone.class.isAssignableFrom(raw)) {
return new TimeZoneSerializer();
}
if (java.nio.charset.Charset.class.isAssignableFrom(raw)) {
return ToStringSerializer.instance;
}
if (Number.class.isAssignableFrom(raw)) {
// 21-May-2014, tatu:
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> Couple of alternatives actually
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
if (format != null) {
switch (format.getShape()) {
case STRING:
return ToStringSerializer.instance;
case OBJECT: // need to bail out to let it be serialized as POJO
case ARRAY: // or, I guess ARRAY; otherwise no point in speculating
return null;
default:
}
}
return NumberSerializer.instance;
}
if (Enum.class.isAssignableFrom(raw)) {
return buildEnumSerializer(prov.getConfig(), type, beanDesc);
}
return null;
}
/**
* Overridable method called after checking all other types.
*
* @since 2.2
*/
protected JsonSerializer<?> findOptionalStdSerializer(SerializerProvider prov,
JavaType type, BeanDescription beanDesc, boolean staticTyping)
throws JsonMappingException
{
return OptionalHandlerFactory.instance.findSerializer(prov.getConfig(), type, beanDesc);
}
/**
* Reflection-based serialized find method, which checks if
* given class implements one of recognized "add-on" interfaces.
* Add-on here means a role that is usually or can be a secondary
* trait: for example,
* bean classes may implement {@link Iterable}, but their main
* function is usually something else. The reason for
*/
protected final JsonSerializer<?> findSerializerByAddonType(SerializationConfig config,
JavaType javaType, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
{
Class<?> type = javaType.getRawClass();
if (Iterator.class.isAssignableFrom(type)) {
JavaType[] params = config.getTypeFactory().findTypeParameters(javaType, Iterator.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIteratorSerializer(config, javaType, beanDesc, staticTyping, vt);
}
if (Iterable.class.isAssignableFrom(type)) {
JavaType[] params = config.getTypeFactory().findTypeParameters(javaType, Iterable.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIterableSerializer(config, javaType, beanDesc
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>, staticTyping, vt);
}
if (CharSequence.class.isAssignableFrom(type)) {
return ToStringSerializer.instance;
}
return null;
}
/**
* Helper method called to check if a class or method
* has an annotation
* (@link com.fasterxml.jackson.databind.annotation.JsonSerialize#using)
* that tells the class to use for serialization.
* Returns null if no such annotation found.
*/
@SuppressWarnings("unchecked")
protected JsonSerializer<Object> findSerializerFromAnnotation(SerializerProvider prov,
Annotated a)
throws JsonMappingException
{
Object serDef = prov.getAnnotationIntrospector().findSerializer(a);
if (serDef == null) {
return null;
}
JsonSerializer<Object> ser = prov.serializerInstance(a, serDef);
// One more thing however: may need to also apply a converter:
return (JsonSerializer<Object>) findConvertingSerializer(prov, a, ser);
}
/**
* Helper method that will check whether given annotated entity (usually class,
* but may also be a property accessor) indicates that a {@link Converter} is to
* be used; and if so, to construct and return suitable serializer for it.
* If not, will simply return given serializer as is.
*/
protected JsonSerializer<?> findConvertingSerializer(SerializerProvider prov,
Annotated a, JsonSerializer<?> ser)
throws JsonMappingException
{
Converter<Object,Object> conv = findConverter(prov, a);
if (conv == null) {
return ser;
}
JavaType delegateType = conv.getOutputType(prov.getTypeFactory());
return new StdDelegatingSerializer(conv, delegateType, ser);
}
protected Converter<Object,Object> findConverter(SerializerProvider prov,
Annotated a)
throws JsonMappingException
{
Object convDef = prov.getAnnotationIntrospector().findSerializationConverter(a);
if (convDef == null) {
return null;
}
return prov.converterInstance(a, convDef);
}
/*
/**********************************************************
/* Factory methods, container types:
/**********************************************************
*/
/**
* @since 2.1
*/
protected JsonSerializer<?> buildContainerSerializer(SerializerProvider prov,
JavaType type, BeanDescription beanDesc, boolean staticTyping)
throws
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> JsonMappingException
{
final SerializationConfig config = prov.getConfig();
/* [databind#23], 15-Mar-2013, tatu: must force static handling of root value type,
* with just one important exception: if value type is "untyped", let's
* leave it as is; no clean way to make it work.
*/
if (!staticTyping && type.useStaticType()) {
if (!type.isContainerType() || type.getContentType().getRawClass() != Object.class) {
staticTyping = true;
}
}
// Let's see what we can learn about element/content/value type, type serializer for it:
JavaType elementType = type.getContentType();
TypeSerializer elementTypeSerializer = createTypeSerializer(config,
elementType);
// if elements have type serializer, can not force static typing:
if (elementTypeSerializer != null) {
staticTyping = false;
}
JsonSerializer<Object> elementValueSerializer = _findContentSerializer(prov,
beanDesc.getClassInfo());
if (type.isMapLikeType()) { // implements java.util.Map
MapLikeType mlt = (MapLikeType) type;
/* 29-Sep-2012, tatu: This is actually too early to (try to) find
* key serializer from property annotations, and can lead to caching
* issues (see [databind#75]). Instead, must be done from 'createContextual()' call.
* But we do need to check class annotations.
*/
JsonSerializer<Object> keySerializer = _findKeySerializer(prov, beanDesc.getClassInfo());
if (mlt.isTrueMapType()) {
return buildMapSerializer(prov, (MapType) mlt, beanDesc, staticTyping,
keySerializer, elementTypeSerializer, elementValueSerializer);
}
// With Map-like, just 2 options: (1) Custom, (2) Annotations
JsonSerializer<?> ser = null;
MapLikeType mlType = (MapLikeType) type;
for (Serializers serializers : customSerializers()) { // (1) Custom
ser = serializers.findMapLikeSerializer(config,
mlType, beanDesc, keySerializer, elementTypeSerializer, elementValueSerializer);
if (ser != null
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>) {
break;
}
}
if (ser == null) { // (2) Annotations-based ones:
ser = findSerializerByAnnotations(prov, type, beanDesc);
}
if (ser != null) {
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifyMapLikeSerializer(config, mlType, beanDesc, ser);
}
}
}
return ser;
}
if (type.isCollectionLikeType()) {
CollectionLikeType clt = (CollectionLikeType) type;
if (clt.isTrueCollectionType()) {
return buildCollectionSerializer(prov, (CollectionType) clt, beanDesc, staticTyping,
elementTypeSerializer, elementValueSerializer);
}
// With Map-like, just 2 options: (1) Custom, (2) Annotations
JsonSerializer<?> ser = null;
CollectionLikeType clType = (CollectionLikeType) type;
for (Serializers serializers : customSerializers()) { // (1) Custom
ser = serializers.findCollectionLikeSerializer(config,
clType, beanDesc, elementTypeSerializer, elementValueSerializer);
if (ser != null) {
break;
}
}
if (ser == null) { // (2) Annotations-based ones:
ser = findSerializerByAnnotations(prov, type, beanDesc);
}
if (ser != null) {
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifyCollectionLikeSerializer(config, clType, beanDesc, ser);
}
}
}
return ser;
}
if (type.isArrayType()) {
return buildArraySerializer(prov, (ArrayType) type, beanDesc, staticTyping,
elementTypeSerializer, elementValueSerializer);
}
return null;
}
/**
* Helper method that handles configuration details when constructing serializers for
* {@link java.util.List} types that support efficient by-index access
*
* @since 2.1
*/
protected JsonSerializer<?> buildCollectionSerializer(SerializerProvider prov,
CollectionType type, BeanDescription beanDesc, boolean staticTyping,
TypeSerializer elementTypeSerializer, JsonSerializer<Object
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>> elementValueSerializer)
throws JsonMappingException
{
SerializationConfig config = prov.getConfig();
JsonSerializer<?> ser = null;
// Order of lookups:
// 1. Custom serializers
// 2. Annotations (@JsonValue, @JsonDeserialize)
// 3. Defaults
for (Serializers serializers : customSerializers()) { // (1) Custom
ser = serializers.findCollectionSerializer(config,
type, beanDesc, elementTypeSerializer, elementValueSerializer);
if (ser != null) {
break;
}
}
if (ser == null) {
ser = findSerializerByAnnotations(prov, type, beanDesc); // (2) Annotations
if (ser == null) {
// We may also want to use serialize Collections "as beans", if (and only if)
// this is specified with `@JsonFormat(shape=Object)`
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
if (format != null && format.getShape() == JsonFormat.Shape.OBJECT) {
return null;
}
Class<?> raw = type.getRawClass();
if (EnumSet.class.isAssignableFrom(raw)) {
// this may or may not be available (Class doesn't; type of field/method does)
JavaType enumType = type.getContentType();
// and even if nominally there is something, only use if it really is enum
if (!enumType.isEnumType()) {
enumType = null;
}
ser = buildEnumSetSerializer(enumType);
} else {
Class<?> elementRaw = type.getContentType().getRawClass();
if (isIndexedList(raw)) {
if (elementRaw == String.class) {
// [JACKSON-829] Must NOT use if we have custom serializer
if (elementValueSerializer == null || ClassUtil.isJacksonStdImpl(elementValueSerializer)) {
ser = IndexedStringListSerializer.instance;
}
} else {
ser = buildIndexedListSerializer(type.getContentType(), staticTyping,
elementTypeSerializer, elementValueSerializer);
}
} else if (elementRaw == String.class) {
// [JACKSON-829] Must NOT use if we have custom serializer
if (elementValueSerializer == null || ClassUtil.isJackson
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>StdImpl(elementValueSerializer)) {
ser = StringCollectionSerializer.instance;
}
}
if (ser == null) {
ser = buildCollectionSerializer(type.getContentType(), staticTyping,
elementTypeSerializer, elementValueSerializer);
}
}
}
}
// [databind#120]: Allow post-processing
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifyCollectionSerializer(config, type, beanDesc, ser);
}
}
return ser;
}
/*
/**********************************************************
/* Factory methods, for Collections
/**********************************************************
*/
protected boolean isIndexedList(Class<?> cls)
{
return RandomAccess.class.isAssignableFrom(cls);
}
public ContainerSerializer<?> buildIndexedListSerializer(JavaType elemType,
boolean staticTyping, TypeSerializer vts, JsonSerializer<Object> valueSerializer) {
return new IndexedListSerializer(elemType, staticTyping, vts, valueSerializer);
}
public ContainerSerializer<?> buildCollectionSerializer(JavaType elemType,
boolean staticTyping, TypeSerializer vts, JsonSerializer<Object> valueSerializer) {
return new CollectionSerializer(elemType, staticTyping, vts, valueSerializer);
}
public JsonSerializer<?> buildEnumSetSerializer(JavaType enumType) {
return new EnumSetSerializer(enumType);
}
/*
/**********************************************************
/* Factory methods, for Maps
/**********************************************************
*/
/**
* Helper method that handles configuration details when constructing serializers for
* {@link java.util.Map} types.
*/
protected JsonSerializer<?> buildMapSerializer(SerializerProvider prov,
MapType type, BeanDescription beanDesc,
boolean staticTyping, JsonSerializer<Object> keySerializer,
TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
throws JsonMappingException
{
final SerializationConfig config = prov.getConfig();
JsonSerializer<?> ser = null;
// Order of lookups:
// 1. Custom serializers
// 2. Annotations (@JsonValue, @JsonDeserialize)
// 3. Defaults
for (Serializers serializers : customSerializers()) { // (1) Custom
ser = serializers.findMapSerializer(config, type, beanDesc,
keySerializer, elementTypeSerializer, elementValueSerializer);
if
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> (ser != null) { break; }
}
if (ser == null) {
ser = findSerializerByAnnotations(prov, type, beanDesc); // (2) Annotations
if (ser == null) {
// 08-Nov-2014, tatu: As per [databind#601], better just use default Map serializer
/*
if (EnumMap.class.isAssignableFrom(type.getRawClass())
&& ((keySerializer == null) || ClassUtil.isJacksonStdImpl(keySerializer))) {
JavaType keyType = type.getKeyType();
// Need to find key enum values...
EnumValues enums = null;
if (keyType.isEnumType()) { // non-enum if we got it as type erased class (from instance)
@SuppressWarnings("unchecked")
Class<Enum<?>> enumClass = (Class<Enum<?>>) keyType.getRawClass();
enums = EnumValues.construct(config, enumClass);
}
ser = new EnumMapSerializer(type.getContentType(), staticTyping, enums,
elementTypeSerializer, elementValueSerializer);
} else {
*/
Object filterId = findFilterId(config, beanDesc);
AnnotationIntrospector ai = config.getAnnotationIntrospector();
MapSerializer mapSer = MapSerializer.construct(ai.findPropertiesToIgnore(beanDesc.getClassInfo(), true),
type, staticTyping, elementTypeSerializer,
keySerializer, elementValueSerializer, filterId);
Object suppressableValue = findSuppressableContentValue(config,
type.getContentType(), beanDesc);
if (suppressableValue != null) {
mapSer = mapSer.withContentInclusion(suppressableValue);
}
ser = mapSer;
}
}
// [databind#120]: Allow post-processing
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifyMapSerializer(config, type, beanDesc, ser);
}
}
return ser;
}
/**
*<p>
* NOTE: although return type is left opaque, it really needs to be
* <code>JsonInclude.Include</code> for things to work as expected.
*
* @since 2.5
*/
protected Object findSuppress
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>ableContentValue(SerializationConfig config,
JavaType contentType, BeanDescription beanDesc)
throws JsonMappingException
{
JsonInclude.Include incl = beanDesc.findSerializationInclusionForContent(null);
if (incl != null) {
switch (incl) {
case NON_DEFAULT:
// 19-Oct-2014, tatu: Not sure what this'd mean; so take it to mean "NON_EMPTY"...
incl = JsonInclude.Include.NON_EMPTY;
break;
default:
// all other modes actually good as is, unless we'll find better ways
break;
}
return incl;
}
return null;
}
/*
/**********************************************************
/* Factory methods, for Arrays
/**********************************************************
*/
/**
* Helper method that handles configuration details when constructing serializers for
* <code>Object[]</code> (and subtypes, except for String).
*/
protected JsonSerializer<?> buildArraySerializer(SerializerProvider prov,
ArrayType type, BeanDescription beanDesc,
boolean staticTyping,
TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
throws JsonMappingException
{
// 25-Jun-2015, tatu: Note that unlike with Collection(Like) and Map(Like) types, array
// types can not be annotated (in theory I guess we could have mix-ins but... ?)
// so we need not do primary annotation lookup here.
// So all we need is (1) Custom, (2) Default array serializers
SerializationConfig config = prov.getConfig();
JsonSerializer<?> ser = null;
for (Serializers serializers : customSerializers()) { // (1) Custom
ser = serializers.findArraySerializer(config,
type, beanDesc, elementTypeSerializer, elementValueSerializer);
if (ser != null) {
break;
}
}
if (ser == null) {
Class<?> raw = type.getRawClass();
// Important: do NOT use standard serializers if non-standard element value serializer specified
if (elementValueSerializer == null || ClassUtil.isJacksonStdImpl(elementValueSerializer)) {
if (String[].class == raw) {
ser = StringArraySerializer.instance;
} else {
// other standard types?
ser = StdArraySerializers.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>class);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException("Failed to widen type "+type+" with concrete-type annotation (value "+superclass.getName()+"), method '"+a.getName()+"': "+iae.getMessage());
}
}
return modifySecondaryTypesByAnnotation(config, a, type);
}
@SuppressWarnings("unchecked")
protected static <T extends JavaType> T modifySecondaryTypesByAnnotation(SerializationConfig config,
Annotated a, T type)
{
AnnotationIntrospector intr = config.getAnnotationIntrospector();
// then key class
if (type.isContainerType()) {
Class<?> keyClass = intr.findSerializationKeyType(a, type.getKeyType());
if (keyClass != null) {
// illegal to use on non-Maps
if (!(type instanceof MapType)) {
throw new IllegalArgumentException("Illegal key-type annotation: type "+type+" is not a Map type");
}
try {
type = (T) ((MapType) type).widenKey(keyClass);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException("Failed to narrow key type "+type+" with key-type annotation ("+keyClass.getName()+"): "+iae.getMessage());
}
}
// and finally content class; only applicable to structured types
Class<?> cc = intr.findSerializationContentType(a, type.getContentType());
if (cc != null) {
try {
type = (T) type.widenContentsBy(cc);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException("Failed to narrow content type "+type+" with content-type annotation ("+cc.getName()+"): "+iae.getMessage());
}
}
}
return type;
}
/**
* Helper method called to try to find whether there is an annotation in the
* class that indicates key serializer to use.
* If so, will try to instantiate key serializer and return it; otherwise returns null.
*/
protected JsonSerializer<Object> _findKeySerializer(SerializerProvider prov,
Annotated a)
throws JsonMappingException
{
AnnotationIntrospector intr = prov.getAnnotationIntrospector();
Object serDef = intr.findKeySerializer(a);
if (serDef != null) {
return prov.serializerInstance(a, serDef);
}
return
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> null;
}
/**
* Helper method called to try to find whether there is an annotation in the
* class that indicates content ("value") serializer to use.
* If so, will try to instantiate key serializer and return it; otherwise returns null.
*/
protected JsonSerializer<Object> _findContentSerializer(SerializerProvider prov,
Annotated a)
throws JsonMappingException
{
AnnotationIntrospector intr = prov.getAnnotationIntrospector();
Object serDef = intr.findContentSerializer(a);
if (serDef != null) {
return prov.serializerInstance(a, serDef);
}
return null;
}
/**
* Method called to find filter that is configured to be used with bean
* serializer being built, if any.
*/
protected Object findFilterId(SerializationConfig config, BeanDescription beanDesc) {
return config.getAnnotationIntrospector().findFilterId((Annotated)beanDesc.getClassInfo());
}
/**
* Helper method to check whether global settings and/or class
* annotations for the bean class indicate that static typing
* (declared types) should be used for properties.
* (instead of dynamic runtime types).
*
* @since 2.1 (earlier had variant with additional 'property' parameter)
*/
protected boolean usesStaticTyping(SerializationConfig config,
BeanDescription beanDesc, TypeSerializer typeSer)
{
/* 16-Aug-2010, tatu: If there is a (value) type serializer, we can not force
* static typing; that would make it impossible to handle expected subtypes
*/
if (typeSer != null) {
return false;
}
AnnotationIntrospector intr = config.getAnnotationIntrospector();
JsonSerialize.Typing t = intr.findSerializationTyping(beanDesc.getClassInfo());
if (t != null && t != JsonSerialize.Typing.DEFAULT_TYPING) {
return (t == JsonSerialize.Typing.STATIC);
}
return config.isEnabled(MapperFeature.USE_STATIC_TYPING);
}
protected Class<?> _verifyAsClass(Object src, String methodName, Class<?> noneClass)
{
if (src == null) {
return null;
}
if (!(src instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector."+methodName+"()
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> {
cfg = cfg.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
} else {
cfg = cfg.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
return cfg;
}
@Override
public SerializationConfig with(HandlerInstantiator hi) {
return _withBase(_base.withHandlerInstantiator(hi));
}
@Override
public SerializationConfig with(PropertyNamingStrategy pns) {
return _withBase(_base.withPropertyNamingStrategy(pns));
}
@Override
public SerializationConfig withRootName(PropertyName rootName) {
if (rootName == null) {
if (_rootName == null) {
return this;
}
} else if (rootName.equals(_rootName)) {
return this;
}
return new SerializationConfig(this, rootName);
}
@Override
public SerializationConfig with(SubtypeResolver str) {
return (str == _subtypeResolver)? this : new SerializationConfig(this, str);
}
@Override
public SerializationConfig with(TypeFactory tf) {
return _withBase(_base.withTypeFactory(tf));
}
@Override
public SerializationConfig with(TypeResolverBuilder<?> trb) {
return _withBase(_base.withTypeResolverBuilder(trb));
}
@Override
public SerializationConfig withView(Class<?> view) {
return (_view == view) ? this : new SerializationConfig(this, view);
}
@Override
public SerializationConfig with(VisibilityChecker<?> vc) {
return _withBase(_base.withVisibilityChecker(vc));
}
@Override
public SerializationConfig withVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility) {
return _withBase(_base.withVisibility(forMethod, visibility));
}
@Override
public SerializationConfig with(Locale l) {
return _withBase(_base.with(l));
}
@Override
public SerializationConfig with(TimeZone tz) {
return _withBase(_base.with(tz));
}
@Override
public SerializationConfig with(Base64Variant base64) {
return _withBase(_base.with(base64));
}
@Override
public SerializationConfig with(ContextAttributes attrs) {
return (attrs == _attributes)
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> pp;
}
/*
/**********************************************************
/* JsonParser initialization
/**********************************************************
*/
/**
* Method called by {@link ObjectMapper} and {@link ObjectWriter}
* to modify those {@link com.fasterxml.jackson.core.JsonGenerator.Feature} settings
* that have been configured via this config instance.
*
* @since 2.5
*/
public void initialize(JsonGenerator g)
{
if (SerializationFeature.INDENT_OUTPUT.enabledIn(_serFeatures)) {
// but do not override an explicitly set one
if (g.getPrettyPrinter() == null) {
PrettyPrinter pp = constructDefaultPrettyPrinter();
if (pp != null) {
g.setPrettyPrinter(pp);
}
}
}
@SuppressWarnings("deprecation")
boolean useBigDec = SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN.enabledIn(_serFeatures);
if ((_generatorFeaturesToChange != 0) || useBigDec) {
int orig = g.getFeatureMask();
int newFlags = (orig & ~_generatorFeaturesToChange) | _generatorFeatures;
// although deprecated, needs to be supported for now
if (useBigDec) {
newFlags |= JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN.getMask();
}
if (orig != newFlags) {
g.setFeatureMask(newFlags);
}
}
}
/*
/**********************************************************
/* MapperConfig implementation/overrides
/**********************************************************
*/
@Override
public boolean useRootWrapping()
{
if (_rootName != null) { // empty String disables wrapping; non-empty enables
return !_rootName.isEmpty();
}
return isEnabled(SerializationFeature.WRAP_ROOT_VALUE);
}
@Override
public AnnotationIntrospector getAnnotationIntrospector()
{
if (isEnabled(MapperFeature.USE_ANNOTATIONS)) {
return super.getAnnotationIntrospector();
}
return AnnotationIntrospector.nopInstance();
}
/**
* Accessor for getting bean description that only contains class
* annotations: useful if no getter/setter/creator information is needed.
*/
@Override
public BeanDescription introspectClassAnnotations(JavaType type) {
return getClassIntrospector().forClassAnnotations(this, type, this);
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> A singleton instance can be used for cloning purposes, as a blueprint of sorts.
*/
public final static StdDateFormat instance = new StdDateFormat();
/**
* Caller may want to explicitly override timezone to use; if so,
* we will have non-null value here.
*/
protected transient TimeZone _timezone;
protected final Locale _locale;
protected transient DateFormat _formatRFC1123;
protected transient DateFormat _formatISO8601;
protected transient DateFormat _formatISO8601_z;
protected transient DateFormat _formatPlain;
/*
/**********************************************************
/* Life cycle, accessing singleton "standard" formats
/**********************************************************
*/
public StdDateFormat() {
_locale = DEFAULT_LOCALE;
}
/**
* @deprecated Since 2.4, use variant that also takes Locale
*/
@Deprecated // since 2.4
public StdDateFormat(TimeZone tz) {
this(tz, DEFAULT_LOCALE);
}
public StdDateFormat(TimeZone tz, Locale loc) {
_timezone = tz;
_locale = loc;
}
public static TimeZone getDefaultTimeZone() {
return DEFAULT_TIMEZONE;
}
/**
* Method used for creating a new instance with specified timezone;
* if no timezone specified, defaults to the default timezone (UTC).
*/
public StdDateFormat withTimeZone(TimeZone tz) {
if (tz == null) {
tz = DEFAULT_TIMEZONE;
}
if (tz.equals(_timezone)) {
return this;
}
return new StdDateFormat(tz, _locale);
}
public StdDateFormat withLocale(Locale loc) {
if (loc.equals(_locale)) {
return this;
}
return new StdDateFormat(_timezone, loc);
}
@Override
public StdDateFormat clone() {
/* Although there is that much state to share, we do need to
* orchestrate a bit, mostly since timezones may be changed
*/
return new StdDateFormat(_timezone, _locale);
}
/**
* Method for getting the globally shared DateFormat instance
* that uses GMT timezone and can handle simple ISO-8601
* compliant date format.
*
* @deprecated Since 2.4 not to be used.
*/
@Deprecated
public static DateFormat getBlueprintISO86
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>01Format() {
return DATE_FORMAT_ISO8601;
}
/**
* @deprecated Since 2.4; use variant that takes Locale
*/
@Deprecated
public static DateFormat getISO8601Format(TimeZone tz) {
return getISO8601Format(tz, DEFAULT_LOCALE);
}
/**
* Method for getting a non-shared DateFormat instance
* that uses specified timezone and can handle simple ISO-8601
* compliant date format.
*
* @since 2.4
*/
public static DateFormat getISO8601Format(TimeZone tz, Locale loc) {
return _cloneFormat(DATE_FORMAT_ISO8601, DATE_FORMAT_STR_ISO8601, tz, loc);
}
/**
* Method for getting the globally shared DateFormat instance
* that uses GMT timezone and can handle RFC-1123
* compliant date format.
*
* @deprecated Since 2.4 not to be used.
*/
@Deprecated
public static DateFormat getBlueprintRFC1123Format() {
return DATE_FORMAT_RFC1123;
}
/**
* Method for getting a non-shared DateFormat instance
* that uses specific timezone and can handle RFC-1123
* compliant date format.
*
* @since 2.4
*/
public static DateFormat getRFC1123Format(TimeZone tz, Locale loc) {
return _cloneFormat(DATE_FORMAT_RFC1123, DATE_FORMAT_STR_RFC1123, tz, loc);
}
/**
* @deprecated Since 2.4; use variant that takes Locale
*/
@Deprecated
public static DateFormat getRFC1123Format(TimeZone tz) {
return getRFC1123Format(tz, DEFAULT_LOCALE);
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
@Override // since 2.6
public TimeZone getTimeZone() {
return _timezone;
}
@Override
public void setTimeZone(TimeZone tz)
{
/* DateFormats are timezone-specific (via Calendar contained),
* so need to reset instances if timezone changes:
*/
if (!tz.equals(_
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>.parse(dateStr, pos);
}
private final static boolean hasTimeZone(String str)
{
// Only accept "+hh", "+hhmm" and "+hh:mm" (and with minus), so
int len = str.length();
if (len >= 6) {
char c = str.charAt(len-6);
if (c == '+' || c == '-') return true;
c = str.charAt(len-5);
if (c == '+' || c == '-') return true;
c = str.charAt(len-3);
if (c == '+' || c == '-') return true;
}
return false;
}
private final static DateFormat _cloneFormat(DateFormat df, String format,
TimeZone tz, Locale loc)
{
if (!loc.equals(DEFAULT_LOCALE)) {
df = new SimpleDateFormat(format, loc);
df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
} else {
df = (DateFormat) df.clone();
if (tz != null) {
df.setTimeZone(tz);
}
}
return df;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> JDK serialization, recovery of Singleton instance
protected Object readResolve() {
if (_simpleName == null || _USE_DEFAULT.equals(_simpleName)) {
return USE_DEFAULT;
}
if (_simpleName.equals(_NO_NAME) && _namespace == null) {
return NO_NAME;
}
return this;
}
/**
* @since 2.6
*/
public static PropertyName construct(String simpleName)
{
if (simpleName == null || simpleName.length() == 0) {
return USE_DEFAULT;
}
return new PropertyName(InternCache.instance.intern(simpleName), null);
}
public static PropertyName construct(String simpleName, String ns)
{
if (simpleName == null) {
simpleName = "";
}
if (ns == null && simpleName.length() == 0) {
return USE_DEFAULT;
}
return new PropertyName(InternCache.instance.intern(simpleName), ns);
}
public PropertyName internSimpleName()
{
if (_simpleName.length() == 0) { // empty String is canonical already
return this;
}
String interned = InternCache.instance.intern(_simpleName);
if (interned == _simpleName) { // was already interned
return this;
}
return new PropertyName(interned, _namespace);
}
/**
* Fluent factory method for constructing an instance with different
* simple name.
*/
public PropertyName withSimpleName(String simpleName)
{
if (simpleName == null) {
simpleName = "";
}
if (simpleName.equals(_simpleName)) {
return this;
}
return new PropertyName(simpleName, _namespace);
}
/**
* Fluent factory method for constructing an instance with different
* namespace.
*/
public PropertyName withNamespace(String ns) {
if (ns == null) {
if (_namespace == null) {
return this;
}
} else if (ns.equals(_namespace)) {
return this;
}
return new PropertyName(_simpleName, ns);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
public String getSimpleName() {
return _simpleName;
}
/**
*
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> Accessor that may be used to get lazily-constructed efficient
* representation of the simple name.
*
* @since 2.4
*/
public SerializableString simpleAsEncoded(MapperConfig<?> config) {
SerializableString sstr = _encodedSimple;
if (sstr == null) {
if (config == null) {
sstr = new SerializedString(_simpleName);
} else {
sstr = config.compileString(_simpleName);
}
_encodedSimple = sstr;
}
return sstr;
}
public String getNamespace() {
return _namespace;
}
public boolean hasSimpleName() {
return _simpleName.length() > 0;
}
/**
* @since 2.3
*/
public boolean hasSimpleName(String str) {
if (str == null) {
return _simpleName == null;
}
return str.equals(_simpleName);
}
public boolean hasNamespace() {
return _namespace != null;
}
/**
* Method that is basically equivalent of:
*<pre>
* !hasSimpleName() && !hasNamespace();
*</pre>
*
* @since 2.4
*/
public boolean isEmpty() {
return (_namespace == null) && (_simpleName.isEmpty());
}
/*
/**********************************************************
/* Std method overrides
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
/* 13-Nov-2012, tatu: by default, require strict type equality.
* Re-evaluate if this becomes an issue.
*/
if (o.getClass() != getClass()) return false;
// 13-Nov-2012, tatu: Should we have specific rules on matching USE_DEFAULT?
// (like, it only ever matching exact instance)
// If we did, would need to check symmetrically; that is, if either 'this'
// or 'o' was USE_DEFAULT, both would have to be.
PropertyName other = (PropertyName) o;
if (_simpleName == null) {
if (other._simpleName != null) return false;
} else
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> if (!_simpleName.equals(other._simpleName)) {
return false;
}
if (_namespace == null) {
return (null == other._namespace);
}
return _namespace.equals(other._namespace);
}
@Override
public int hashCode() {
if (_namespace == null) {
return _simpleName.hashCode();
}
return _namespace.hashCode() ^ _simpleName.hashCode();
}
@Override
public String toString() {
if (_namespace == null) {
return _simpleName;
}
return "{"+_namespace + "}" + _simpleName;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.util.Arrays;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains Base64 encoded binary value, which will be
* output and stored as Json String value.
*/
public class BinaryNode
extends ValueNode
{
final static BinaryNode EMPTY_BINARY_NODE = new BinaryNode(new byte[0]);
protected final byte[] _data;
public BinaryNode(byte[] data)
{
_data = data;
}
public BinaryNode(byte[] data, int offset, int length)
{
if (offset == 0 && length == data.length) {
_data = data;
} else {
_data = new byte[length];
System.arraycopy(data, offset, _data, 0, length);
}
}
public static BinaryNode valueOf(byte[] data)
{
if (data == null) {
return null;
}
if (data.length == 0) {
return EMPTY_BINARY_NODE;
}
return new BinaryNode(data);
}
public static BinaryNode valueOf(byte[] data, int offset, int length)
{
if (data == null) {
return null;
}
if (length == 0) {
return EMPTY_BINARY_NODE;
}
return new BinaryNode(data, offset, length);
}
@Override
public JsonNodeType getNodeType()
{
return JsonNodeType.BINARY;
}
@Override
public JsonToken asToken() {
/* No distinct type; could use one for textual values,
* but given that it's not in text form at this point,
* embedded-object is closest
*/
return JsonToken.VALUE_EMBEDDED_OBJECT;
}
/**
*<p>
* Note: caller is not to modify returned array in any way, since
* it is not a copy but reference to the underlying byte array.
*/
@Override
public byte[] binaryValue() { return _data; }
/**
* Hmmh. This is not quite as efficient as using {@link #serialize},
* but will work correctly.
*/
@Override
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
public String asText() {
return Base64Variants.getDefaultVariant().encode(_data, false);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeBinary(provider.getConfig().getBase64Variant(),
_data, 0, _data.length);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BinaryNode)) {
return false;
}
return Arrays.equals(((BinaryNode) o)._data, _data);
}
@Override
public int hashCode() {
return (_data == null) ? -1 : _data.length;
}
/**
* Different from other values, since contents need to be surrounded
* by (double) quotes.
*/
@Override
public String toString()
{
return Base64Variants.getDefaultVariant().encode(_data, true);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind;
/**
* Simple container class used for storing "additional" metadata about
* properties. Carved out to reduce number of distinct properties that
* actual property implementations and placeholders need to store;
* since instances are immutable, they can be freely shared.
*
* @since 2.3
*/
public class PropertyMetadata
implements java.io.Serializable
{
private static final long serialVersionUID = -1;
public final static PropertyMetadata STD_REQUIRED = new PropertyMetadata(Boolean.TRUE, null, null, null);
public final static PropertyMetadata STD_OPTIONAL = new PropertyMetadata(Boolean.FALSE, null, null, null);
public final static PropertyMetadata STD_REQUIRED_OR_OPTIONAL = new PropertyMetadata(null, null, null, null);
/**
* Three states: required, not required and unknown; unknown represented
* as null.
*/
protected final Boolean _required;
/**
* Optional human-readable description associated with the property.
*/
protected final String _description;
/**
* Optional index of the property within containing Object.
*
* @since 2.4
*/
protected final Integer _index;
/**
* Optional default value, as String, for property; not used cor
* any functionality by core databind, offered as metadata for
* extensions.
*/
protected final String _defaultValue;
/*
/**********************************************************
/* Construction, configuration
/**********************************************************
*/
@Deprecated // since 2.4
protected PropertyMetadata(Boolean req, String desc) { this(req, desc, null, null); }
/**
* @since 2.5
*/
protected PropertyMetadata(Boolean req, String desc, Integer index, String def)
{
_required = req;
_description = desc;
_index = index;
_defaultValue = (def == null || def.isEmpty()) ? null : def;
}
/**
* @since 2.4 Use variant that takes more arguments.
*/
@Deprecated
public static PropertyMetadata construct(boolean req, String desc) {
return construct(req, desc, null, null);
}
public static PropertyMetadata construct(boolean req, String desc, Integer index,
String defaultValue) {
if (desc != null || index != null || defaultValue != null) {
return new
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> PropertyMetadata(req, desc, index, defaultValue);
}
return req ? STD_REQUIRED : STD_OPTIONAL;
}
/**
* Minor optimization: let's canonicalize back to placeholders in cases
* where there is no real data to consider
*/
protected Object readResolve()
{
if (_description == null && _index == null && _defaultValue == null) {
if (_required == null) {
return STD_REQUIRED_OR_OPTIONAL;
}
return _required.booleanValue() ? STD_REQUIRED : STD_OPTIONAL;
}
return this;
}
public PropertyMetadata withDescription(String desc) {
return new PropertyMetadata(_required, desc, _index, _defaultValue);
}
public PropertyMetadata withDefaultValue(String def) {
if ((def == null) || def.isEmpty()) {
if (_defaultValue == null) {
return this;
}
def = null;
} else if (_defaultValue.equals(def)) {
return this;
}
return new PropertyMetadata(_required, _description, _index, def);
}
public PropertyMetadata withIndex(Integer index) {
return new PropertyMetadata(_required, _description, index, _defaultValue);
}
public PropertyMetadata withRequired(Boolean b) {
if (b == null) {
if (_required == null) {
return this;
}
} else {
if (_required != null && _required.booleanValue() == b.booleanValue()) {
return this;
}
}
return new PropertyMetadata(b, _description, _index, _defaultValue);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
public String getDescription() { return _description; }
/**
* @since 2.5
*/
public String getDefaultValue() { return _defaultValue; }
/**
* @deprecated Since 2.6: typo in name, use {@link #hasDefaultValue()} instead.
*/
@Deprecated
public boolean hasDefuaultValue() { return hasDefaultValue(); }
/**
* Accessor for determining whether property has declared "default value",
* which may be used by extension modules.
*
* @since 2.6
*/
public boolean hasDefaultValue() { return (_defaultValue != null); }
public boolean isRequired() { return (_required != null) &&
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Object, ?> getConverter() {
return _converter;
}
@Override
public JsonSerializer<?> getDelegatee() {
return _delegateSerializer;
}
/*
/**********************************************************
/* Serialization
/**********************************************************
*/
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
Object delegateValue = convertValue(value);
// should we accept nulls?
if (delegateValue == null) {
provider.defaultSerializeNull(gen);
return;
}
// 02-Apr-2015, tatu: As per [databind#731] may need to do dynamic lookup
JsonSerializer<Object> ser = _delegateSerializer;
if (ser == null) {
ser = _findSerializer(delegateValue, provider);
}
ser.serialize(delegateValue, gen, provider);
}
@Override
public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
/* 03-Oct-2012, tatu: This is actually unlikely to work ok... but for now,
* let's give it a chance?
*/
Object delegateValue = convertValue(value);
JsonSerializer<Object> ser = _delegateSerializer;
if (ser == null) {
ser = _findSerializer(value, provider);
}
ser.serializeWithType(delegateValue, gen, provider, typeSer);
}
@Override
@Deprecated // since 2.5
public boolean isEmpty(Object value) {
return isEmpty(null, value);
}
@Override
public boolean isEmpty(SerializerProvider prov, Object value)
{
Object delegateValue = convertValue(value);
if (_delegateSerializer == null) { // best we can do for now, too costly to look up
return (value == null);
}
return _delegateSerializer.isEmpty(prov, delegateValue);
}
/*
/**********************************************************
/* Schema functionality
/**********************************************************
*/
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
if (_delegateSerializer instanceof SchemaAware) {
return ((SchemaAware) _delegateSerializer).getSchema(provider, typeHint);
}
return super.getSchema(provider, typeHint);
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>() { return _field.getDeclaringClass(); }
@Override
public Member getMember() { return _field; }
@Override
public void setValue(Object pojo, Object value) throws IllegalArgumentException
{
try {
_field.set(pojo, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to setValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException
{
try {
return _field.get(pojo);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to getValue() for field "
+getFullName()+": "+e.getMessage(), e);
}
}
/*
/**********************************************************
/* Extended API, generic
/**********************************************************
*/
public String getFullName() {
return getDeclaringClass().getName() + "#" + getName();
}
public int getAnnotationCount() { return _annotations.size(); }
/**
* @since 2.6
*/
public boolean isTransient() { return Modifier.isTransient(getModifiers()); }
@Override
public int hashCode() {
return _field.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedField) o)._field == _field;
}
@Override
public String toString() {
return "[field "+getFullName()+"]";
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedField(new Serialization(_field));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Field f = clazz.getDeclaredField(_serialization.name);
// 06-Oct-2012, tatu: Has "lost" its security override, may need to force back
if (!f.isAccessible()) {
ClassUtil.checkAndFixAccess(f);
}
return new AnnotatedField(null, f, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find method '"+_serialization.name
+"' from Class '"+clazz.getName
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> (m != null) {
Object filterId = intr.findFilterId(m);
if (filterId != null) {
mser = mser.withFilterId(filterId);
}
}
}
return mser;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _valueType;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _valueSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, Map<?,?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(Map<?,?> value) {
return (value.size() == 1);
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Accessor for currently assigned key serializer. Note that
* this may return null during construction of <code>MapSerializer</code>:
* depedencies are resolved during {@link #createContextual} method
* (which can be overridden by custom implementations), but for some
* dynamic types, it is possible that serializer is only resolved
* during actual serialization.
*
* @since 2.0
*/
public JsonSerializer<?> getKeySerializer() {
return _keySerializer;
}
/*
/**********************************************************
/* JsonSerializer implementation
/**********************************************************
*/
@Override
public void serialize(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
gen.writeStartObject();
// [databind#631]: Assign current value, to be accessible by custom serializers
gen.setCurrentValue(value);
if (!value.isEmpty()) {
Object suppressableValue = _suppressableValue;
if (suppressableValue == JsonInclude.Include.ALWAYS) {
suppressableValue = null;
} else if (suppressableValue == null) {
if (!provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES)) {
suppressableValue = JsonInclude.Include.NON_NULL;
}
}
if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) {
value = _orderEntries(value);
}
if (_filterId != null) {
serializeFilteredFields(
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>value, gen, provider,
findPropertyFilter(provider, _filterId, value), suppressableValue);
} else if (suppressableValue != null) {
serializeOptionalFields(value, gen, provider, suppressableValue);
} else if (_valueSerializer != null) {
serializeFieldsUsing(value, gen, provider, _valueSerializer);
} else {
serializeFields(value, gen, provider);
}
}
gen.writeEndObject();
}
@Override
public void serializeWithType(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException
{
typeSer.writeTypePrefixForObject(value, gen);
// [databind#631]: Assign current value, to be accessible by custom serializers
gen.setCurrentValue(value);
if (!value.isEmpty()) {
Object suppressableValue = _suppressableValue;
if (suppressableValue == JsonInclude.Include.ALWAYS) {
suppressableValue = null;
} else if (suppressableValue == null) {
if (!provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES)) {
suppressableValue = JsonInclude.Include.NON_NULL;
}
}
if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) {
value = _orderEntries(value);
}
if (_filterId != null) {
serializeFilteredFields(value, gen, provider,
findPropertyFilter(provider, _filterId, value), suppressableValue);
} else if (suppressableValue != null) {
serializeOptionalFields(value, gen, provider, suppressableValue);
} else if (_valueSerializer != null) {
serializeFieldsUsing(value, gen, provider, _valueSerializer);
} else {
serializeFields(value, gen, provider);
}
}
typeSer.writeTypeSuffixForObject(value, gen);
}
/*
/**********************************************************
/* JsonSerializer implementation
/**********************************************************
*/
/**
* Method called to serialize fields, when the value type is not statically known;
* but we know that no value suppression is needed (which simplifies processing a bit)
*/
public void serializeFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Entry<?,?> entry : value.entrySet()) {
// First find key serializer
final Object keyElem = entry.getKey();
JsonSerializer<Object> keySerializer;
if (keyElem == null) {
keySerializer = provider.findNullKeySerializer(_keyType, _property);
} else {
if (ignored != null && ignored.contains(keyElem)) continue;
keySerializer = _keySerializer;
}
// Then value serializer
final Object valueElem = entry.getValue();
JsonSerializer<Object> valueSer;
if (valueElem == null) {
if (suppressableValue != null) { // all suppressions include null-suppression
continue;
}
valueSer = provider.getDefaultNullValueSerializer();
} else {
valueSer = _valueSerializer;
if (valueSer == null) {
Class<?> cc = valueElem.getClass();
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, valueElem)) {
continue;
}
}
// and then serialize, if all went well
try {
keySerializer.serialize(keyElem, gen, provider);
valueSer.serialize(valueElem, gen, provider);
} catch (Exception e) {
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
/**
* Method called to serialize fields, when the value type is statically known,
* so that value serializer is passed and does not need to be fetched from
* provider.
*/
protected void serializeFieldsUsing(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException
{
final JsonSerializer<Object> keySerializer = _keySerializer;
final HashSet<String> ignored = _ignoredEntries;
final TypeSerializer typeSer = _
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> else {
valueSer = _valueSerializer;
if (valueSer == null) {
Class<?> cc = valueElem.getClass();
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, valueElem)) {
continue;
}
}
// and with that, ask filter to handle it
prop.reset(keyElem, keySerializer, valueSer);
try {
filter.serializeAsField(valueElem, gen, provider, prop);
} catch (Exception e) {
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
@Deprecated // since 2.5
public void serializeFilteredFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
PropertyFilter filter) throws IOException {
serializeFilteredFields(value, gen, provider, filter,
provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES) ? null : JsonInclude.Include.NON_NULL);
}
/**
* @since 2.5
*/
protected void serializeTypedFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
Object suppressableValue) // since 2.5
throws IOException
{
final HashSet<String> ignored = _ignoredEntries;
PropertySerializerMap serializers = _dynamicValueSerializers;
for (Map.Entry<?,?> entry : value.entrySet()) {
Object keyElem = entry.getKey();
JsonSerializer<Object> keySerializer;
if (keyElem == null) {
keySerializer = provider.findNullKeySerializer(_keyType, _property);
} else {
// One twist: is entry ignorable? If so, skip
if (ignored != null && ignored.contains(keyElem)) continue;
keySerializer = _keySerializer;
}
final Object
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> valueElem = entry.getValue();
// And then value
JsonSerializer<Object> valueSer;
if (valueElem == null) {
if (suppressableValue != null) { // all suppression include null suppression
continue;
}
valueSer = provider.getDefaultNullValueSerializer();
} else {
valueSer = _valueSerializer;
Class<?> cc = valueElem.getClass();
valueSer = serializers.serializerFor(cc);
if (valueSer == null) {
if (_valueType.hasGenericTypes()) {
valueSer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_valueType, cc), provider);
} else {
valueSer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicValueSerializers;
}
// also may need to skip non-empty values:
if ((suppressableValue == JsonInclude.Include.NON_EMPTY)
&& valueSer.isEmpty(provider, valueElem)) {
continue;
}
}
keySerializer.serialize(keyElem, gen, provider);
try {
valueSer.serializeWithType(valueElem, gen, provider, _valueTypeSerializer);
} catch (Exception e) {
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
@Deprecated // since 2.5
protected void serializeTypedFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
serializeTypedFields(value, gen, provider,
provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES) ? null : JsonInclude.Include.NON_NULL);
}
/*
/**********************************************************
/* Schema related functionality
/**********************************************************
*/
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
ObjectNode o = createSchemaNode("object", true);
//(ryan) even though it's possible to statically determine the "value" type of the map,
// there's no way to statically determine the keys, so the "Entries" can't be determined.
return o;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
JsonMapFormatVisitor v2 = (visitor ==
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>_NULL) return false;
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if (t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (jp.getNumberType() == NumberType.INT) {
return (jp.getIntValue() != 0);
}
return _parseBooleanFromNumber(jp, ctxt);
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
// [#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return true;
}
if ("false".equals(text) || "False".equals(text) || text.length() == 0) {
return false;
}
if (_hasTextualNull(text)) {
return false;
}
throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final boolean parsed = _parseBooleanPrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'boolean' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Boolean _parseBoolean(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
}
if (t == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
}
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if (
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (p.getNumberType() == NumberType.INT) {
return (p.getIntValue() == 0) ? Boolean.FALSE : Boolean.TRUE;
}
return Boolean.valueOf(_parseBooleanFromNumber(p, ctxt));
}
if (t == JsonToken.VALUE_NULL) {
return (Boolean) getNullValue(ctxt);
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = p.getText().trim();
// [#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return Boolean.TRUE;
}
if ("false".equals(text) || "False".equals(text)) {
return Boolean.FALSE;
}
if (text.length() == 0) {
return (Boolean) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Boolean) getNullValue(ctxt);
}
throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Boolean parsed = _parseBoolean(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Boolean' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final boolean _parseBooleanFromNumber(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
if (jp.getNumberType() == NumberType.LONG) {
return (jp.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
}
// no really good logic; let's
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> actually resort to textual comparison
String str = jp.getText();
if ("0.0".equals(str) || "0".equals(str)) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
protected Byte _parseByte(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getByteValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return (Byte) getNullValue(ctxt);
}
int value;
try {
int len = text.length();
if (len == 0) {
return (Byte) getEmptyValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Byte value");
}
// So far so good: but does it fit?
// as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 8-bit value");
}
return Byte.valueOf((byte) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Byte");
}
return p.getByteValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Byte) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Byte parsed = _parseByte(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
protected Short _parseShort(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getShortValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
int value;
try {
int len = text.length();
if (len == 0) {
return (Short) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Short) getNullValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Short value");
}
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((short) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Short");
}
return p.getShortValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Short) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Short parsed = _parseShort(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> single value array for single 'Short' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
protected final short _parseShortPrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
int value = _parseIntPrimitive(jp, ctxt);
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdStringException(String.valueOf(value),
_valueClass, "overflow, value can not be represented as 16-bit value");
}
return (short) value;
}
protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getIntValue();
}
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return 0;
}
try {
int len = text.length();
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass,
"Overflow: numeric value ("+text+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return (int) l;
}
if (len == 0) {
return 0;
}
return NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid int value");
}
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "int");
}
return p.getValueAsInt();
}
if (t == JsonToken.VALUE_NULL)
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> {
return 0;
}
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final int parsed = _parseIntPrimitive(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'int' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return Integer.valueOf(p.getIntValue());
case JsonTokenId.ID_NUMBER_FLOAT: // coercing may work too
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Integer");
}
return Integer.valueOf(p.getValueAsInt());
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
try {
int len = text.length();
if (_hasTextualNull(text)) {
return (Integer) getNullValue(ctxt);
}
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass,
"Overflow: numeric value ("+text+") out of range of Integer ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return Integer.valueOf((int) l);
}
if (len == 0) {
return (Integer) getEmptyValue(ctxt);
}
return Integer.valueOf(NumberInput.parseInt(text));
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> _valueClass, "not a valid Integer value");
}
case JsonTokenId.ID_NULL:
return (Integer) getNullValue(ctxt);
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Integer parsed = _parseInteger(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Integer' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final Long _parseLong(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return p.getLongValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Long");
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
// let's allow Strings to be converted too
// !!! 05-Jan-2009, tatu: Should we try to limit value space, JDK is too lenient?
String text = p.getText().trim();
if (text.length() == 0) {
return (Long) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Long) getNullValue(ctxt);
}
try {
return Long.valueOf(NumberInput.parseLong(text));
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Long value");
case JsonTokenId.ID_NULL:
return (Long) getNullValue(ctxt);
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Long parsed = _parseLong(p, ctxt);
JsonToken t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Long' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
return p.getLongValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "long");
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
String text = p.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0L;
}
try {
return NumberInput.parseLong(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid long value");
case JsonTokenId.ID_NULL:
return 0L;
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final long parsed = _parseLongPrimitive(p, ctxt);
JsonToken t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'long' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final Float _parseFloat(JsonParser jp,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>valueClass,
"not a valid representation (error: "+iae.getMessage()+")");
}
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Date parsed = _parseDate(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.util.Date' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
/**
* Helper method for encapsulating calls to low-level double value parsing; single place
* just because we need a work-around that must be applied to all calls.
*/
protected final static double parseDouble(String numStr) throws NumberFormatException
{
// [JACKSON-486]: avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE?
// for now, MIN_VALUE, since MIN_NORMAL is JDK 1.6
if (NumberInput.NASTY_SMALL_DOUBLE.equals(numStr)) {
return Double.MIN_VALUE;
}
return Double.parseDouble(numStr);
}
/**
* Helper method used for accessing String value, if possible, doing
* necessary conversion or throwing exception as necessary.
*
* @since 2.1
*/
protected final String _parseString(JsonParser jp, DeserializationContext ctxt) throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
return jp.getText();
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final String parsed = _parseString(jp, ctxt);
if (jp.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'String' value
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> but there was more than a single value in the array");
}
return parsed;
}
String value = jp.getValueAsString();
if (value != null) {
return value;
}
throw ctxt.mappingException(String.class, jp.getCurrentToken());
}
/**
* Helper method that may be used to support fallback for Empty String / Empty Array
* non-standard representations; usually for things serialized as JSON Objects.
*
* @since 2.5
*/
protected T _deserializeFromEmpty(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.START_ARRAY) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
t = jp.nextToken();
if (t == JsonToken.END_ARRAY) {
return null;
}
throw ctxt.mappingException(handledType(), JsonToken.START_ARRAY);
}
} else if (t == JsonToken.VALUE_STRING) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = jp.getText().trim();
if (str.isEmpty()) {
return null;
}
}
}
throw ctxt.mappingException(handledType());
}
/**
* Helper method called to determine if we are seeing String value of
* "null", and, further, that it should be coerced to null just like
* null token.
*
* @since 2.3
*/
protected boolean _hasTextualNull(String value) {
return "null".equals(value);
}
protected final boolean _isNegInf(String text) {
return "-Infinity".equals(text) || "-INF".equals(text);
}
protected final boolean _isPosInf(String text) {
return "Infinity".equals(text) || "INF".equals(text);
}
protected final boolean _isNaN(String text) { return "NaN".equals(text); }
/*
/****************************************************
/* Helper methods for sub-classes, coercions
/****************************************************
*/
/**
* Helper method called in case where an integral number is encountered, but
* config settings suggest that a co
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* This singleton value class is used to contain explicit JSON null
* value.
*/
public final class NullNode
extends ValueNode
{
// // Just need a fly-weight singleton
public final static NullNode instance = new NullNode();
private NullNode() { }
public static NullNode getInstance() { return instance; }
@Override
public JsonNodeType getNodeType()
{
return JsonNodeType.NULL;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_NULL; }
@Override public String asText(String defaultValue) { return defaultValue; }
@Override public String asText() { return "null"; }
// as with MissingNode, not considered number node; hence defaults are returned if provided
/*
public int asInt(int defaultValue);
public long asLong(long defaultValue);
public double asDouble(double defaultValue);
public boolean asBoolean(boolean defaultValue);
*/
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
provider.defaultSerializeNull(jg);
}
@Override
public boolean equals(Object o)
{
return (o == this);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
@JacksonStdImpl
@SuppressWarnings("serial")
public class IterableSerializer
extends AsArraySerializerBase<Iterable<?>>
{
public IterableSerializer(JavaType elemType, boolean staticTyping,
TypeSerializer vts) {
super(Iterable.class, elemType, staticTyping, vts, null);
}
public IterableSerializer(IterableSerializer src, BeanProperty property,
TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts) {
return new IterableSerializer(this, _property, vts, _elementSerializer, _unwrapSingle);
}
@Override
public IterableSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new IterableSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
@Override
public boolean isEmpty(SerializerProvider prov, Iterable<?> value) {
// Not really good way to implement this, but has to do for now:
return (value == null) || !value.iterator().hasNext();
}
@Override
public boolean hasSingleElement(Iterable<?> value) {
// we can do it actually (fixed in 2.3.1)
if (value != null) {
Iterator<?> it = value.iterator();
if (it.hasNext()) {
it.next();
if (!it.hasNext()) {
return true;
}
}
}
return false;
}
@Override
public final void serialize(Iterable<?> value, JsonGenerator gen,
SerializerProvider provider)throws IOException
{
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 32-bit integer values.
*/
public class IntNode
extends NumericNode
{
// // // Let's cache small set of common value
final static int MIN_CANONICAL = -1;
final static int MAX_CANONICAL = 10;
private final static IntNode[] CANONICALS;
static {
int count = MAX_CANONICAL - MIN_CANONICAL + 1;
CANONICALS = new IntNode[count];
for (int i = 0; i < count; ++i) {
CANONICALS[i] = new IntNode(MIN_CANONICAL + i);
}
}
/**
* Integer value this node contains
*/
protected final int _value;
/*
************************************************
* Construction
************************************************
*/
public IntNode(int v) { _value = v; }
public static IntNode valueOf(int i) {
if (i > MAX_CANONICAL || i < MIN_CANONICAL) return new IntNode(i);
return CANONICALS[i - MIN_CANONICAL];
}
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.INT; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isInt() { return true; }
@Override public boolean canConvertToInt() { return true; }
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Integer.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>; }
@Override
public int intValue() { return _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
public double doubleValue() { return (double) _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value != 0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof IntNode) {
return ((IntNode) o)._value == _value;
}
return false;
}
@Override
public int hashCode() { return _value; }
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> _asStatic);
}
/**
* Method that can be used for checking whether this type is a
* "real" Collection type; meaning whether it represents a parameterized
* subtype of {@link java.util.Collection} or just something that acts
* like one.
*/
public boolean isTrueMapType() {
return Map.class.isAssignableFrom(_class);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
return "[map-like type; class "+_class.getName()+", "+_keyType+" -> "+_valueType+"]";
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
MapLikeType other = (MapLikeType) o;
return (_class == other._class)
&& _keyType.equals(other._keyType)
&& _valueType.equals(other._valueType);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> return null; }
/**
* Returns 16-bit short value for this node, <b>if and only if</b>
* this node is numeric ({@link #isNumber} returns true). For other
* types returns 0.
* For floating-point numbers, value is truncated using default
* Java coercion, similar to how cast from double to short operates.
*
* @return Short value this node contains, if any; 0 for non-number
* nodes.
*/
public short shortValue() { return 0; }
/**
* Returns integer value for this node, <b>if and only if</b>
* this node is numeric ({@link #isNumber} returns true). For other
* types returns 0.
* For floating-point numbers, value is truncated using default
* Java coercion, similar to how cast from double to int operates.
*
* @return Integer value this node contains, if any; 0 for non-number
* nodes.
*/
public int intValue() { return 0; }
/**
* Returns 64-bit long value for this node, <b>if and only if</b>
* this node is numeric ({@link #isNumber} returns true). For other
* types returns 0.
* For floating-point numbers, value is truncated using default
* Java coercion, similar to how cast from double to long operates.
*
* @return Long value this node contains, if any; 0 for non-number
* nodes.
*/
public long longValue() { return 0L; }
/**
* Returns 32-bit floating value for this node, <b>if and only if</b>
* this node is numeric ({@link #isNumber} returns true). For other
* types returns 0.0.
* For integer values, conversion is done using coercion; this means
* that an overflow is possible for `long` values
*
* @return 32-bit float value this node contains, if any; 0.0 for non-number nodes.
*
* @since 2.2
*/
public float floatValue() { return 0.0f; }
/**
* Returns 64-
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an int (including structured types
* like Objects and Arrays),
* specified <b>defaultValue</b> will be returned; no exceptions are thrown.
*/
public int asInt(int defaultValue) {
return defaultValue;
}
/**
* Method that will try to convert value of this node to a Java <b>long</b>.
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an long (including structured types
* like Objects and Arrays),
* default value of <b>0</b> will be returned; no exceptions are thrown.
*/
public long asLong() {
return asLong(0L);
}
/**
* Method that will try to convert value of this node to a Java <b>long</b>.
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an long (including structured types
* like Objects and Arrays),
* specified <b>defaultValue</b> will be returned; no exceptions are thrown.
*/
public long asLong(long defaultValue) {
return defaultValue;
}
/**
* Method that will try to convert value of this node to a Java <b>double</b>.
* Numbers are coerced using default Java rules; booleans convert to 0.0 (false)
* and 1.0 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an int (including structured types
* like Objects and Arrays),
* default value of <b>0.0</b> will be returned; no exceptions are thrown.
*/
public double asDouble() {
return asDouble(0.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> @since 2.6
*/
public boolean equals(Comparator<JsonNode> comparator, JsonNode other) {
return comparator.compare(this, other) == 0;
}
/*
/**********************************************************
/* Overridden standard methods
/**********************************************************
*/
/**
*<p>
* Note: marked as abstract to ensure all implementation
* classes define it properly.
*/
@Override
public abstract String toString();
/**
* Equality for node objects is defined as full (deep) value
* equality. This means that it is possible to compare complete
* JSON trees for equality by comparing equality of root nodes.
*<p>
* Note: marked as abstract to ensure all implementation
* classes define it properly and not rely on definition
* from {@link java.lang.Object}.
*/
@Override
public abstract boolean equals(Object o);
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.cfg;
import java.util.*;
/**
* Helper class used for storing and accessing per-call attributes.
* Storage is two-layered: at higher precedence, we have actual per-call
* attributes; and at lower precedence, default attributes that may be
* defined for Object readers and writers.
*<p>
* Note that the way mutability is implemented differs between kinds
* of attributes, to account for thread-safety: per-call attributes
* are handled assuming that instances are never shared, whereas
* changes to per-reader/per-writer attributes are made assuming
* sharing, by creating new copies instead of modifying state.
* This allows sharing of default values without per-call copying, but
* requires two-level lookup on access.
*
* @since 2.3
*/
public abstract class ContextAttributes
{
public static ContextAttributes getEmpty() {
return Impl.getEmpty();
}
/*
/**********************************************************
/* Per-reader/writer access
/**********************************************************
*/
public abstract ContextAttributes withSharedAttribute(Object key, Object value);
public abstract ContextAttributes withSharedAttributes(Map<Object,Object> attributes);
public abstract ContextAttributes withoutSharedAttribute(Object key);
/*
/**********************************************************
/* Per-operation (serialize/deserialize) access
/**********************************************************
*/
/**
* Accessor for value of specified attribute
*/
public abstract Object getAttribute(Object key);
/**
* Mutator used during call (via context) to set value of "non-shared"
* part of attribute set.
*/
public abstract ContextAttributes withPerCallAttribute(Object key, Object value);
/*
/**********************************************************
/* Default implementation
/**********************************************************
*/
public static class Impl extends ContextAttributes
implements java.io.Serializable // just so ObjectReader/ObjectWriter can retain configs
{
private static final long serialVersionUID = 1L;
protected final static Impl EMPTY = new Impl(Collections.emptyMap());
protected final static Object NULL_SURROGATE = new Object();
/**
* Shared attributes that we can not modify in-place.
*/
protected final Map<Object,Object> _shared;
/**
* Per-call attributes that we can directly modify, since they are not
* shared between
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> threads.
*/
protected transient Map<Object,Object> _nonShared;
/*
/**********************************************************
/* Construction, factory methods
/**********************************************************
*/
protected Impl(Map<Object,Object> shared) {
_shared = shared;
_nonShared = null;
}
protected Impl(Map<Object,Object> shared, Map<Object,Object> nonShared) {
_shared = shared;
_nonShared = nonShared;
}
public static ContextAttributes getEmpty() {
return EMPTY;
}
/*
/**********************************************************
/* Per-reader/writer mutant factories
/**********************************************************
*/
@Override
public ContextAttributes withSharedAttribute(Object key, Object value)
{
Map<Object,Object> m;
// need to cover one special case, since EMPTY uses Immutable map:
if (this == EMPTY) {
m = new HashMap<Object,Object>(8);
} else {
m = _copy(_shared);
}
m.put(key, value);
return new Impl(m);
}
@Override
public ContextAttributes withSharedAttributes(Map<Object, Object> shared) {
return new Impl(shared);
}
@Override
public ContextAttributes withoutSharedAttribute(Object key)
{
// first couple of trivial optimizations
if (_shared.isEmpty()) {
return this;
}
if (_shared.containsKey(key)) {
if (_shared.size() == 1) {
return EMPTY;
}
} else { // if we didn't have it anyway, return as-is
return this;
}
// otherwise make copy, modify
Map<Object,Object> m = _copy(_shared);
m.remove(key);
return new Impl(m);
}
/*
/**********************************************************
/* Per-call access
/**********************************************************
*/
@Override
public Object getAttribute(Object key)
{
if (_nonShared != null) {
Object ob = _nonShared.get(key);
if (ob != null) {
if (ob == NULL_SURROGATE) {
return null;
}
return ob;
}
}
return _shared.get(key);
}
@Override
public ContextAttributes withPerCallAttribute(Object key, Object value)
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> != null) {
objectIdInfo = intr.findObjectReferenceInfo(accessor,
new ObjectIdInfo(NAME_FOR_OBJECT_REF, null, null, null));
oiw = _objectIdWriter.withAlwaysAsId(objectIdInfo.getAlwaysAsId());
}
} else {
/* Ugh: mostly copied from BeanSerializerBase: but can't easily
* change it to be able to move to SerializerProvider (where it
* really belongs)
*/
// 2.1: allow modifications by "id ref" annotations as well:
objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo);
ObjectIdGenerator<?> gen;
Class<?> implClass = objectIdInfo.getGeneratorType();
JavaType type = provider.constructType(implClass);
JavaType idType = provider.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
// Property-based generator is trickier
if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
String propName = objectIdInfo.getPropertyName().getSimpleName();
BeanPropertyWriter idProp = null;
for (int i = 0, len = _props.length ;; ++i) {
if (i == len) {
throw new IllegalArgumentException("Invalid Object Id definition for "+_handledType.getName()
+": can not find property with name '"+propName+"'");
}
BeanPropertyWriter prop = _props[i];
if (propName.equals(prop.getName())) {
idProp = prop;
/* Let's force it to be the first property to output
* (although it may still get rearranged etc)
*/
if (i > 0) { // note: must shuffle both regular properties and filtered
System.arraycopy(_props, 0, _props, 1, i);
_props[0] = idProp;
if (_filteredProps != null) {
BeanPropertyWriter fp = _filteredProps[i];
System.arraycopy(_filteredProps, 0, _filteredProps, 1, i);
_filteredProps[0] = fp;
}
}
break;
}
}
idType = idProp.getType();
gen = new PropertyBasedObjectIdGenerator(objectIdInfo, idProp);
oiw = ObjectId
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Writer.construct(idType, (PropertyName) null, gen, objectIdInfo.getAlwaysAsId());
} else { // other types need to be simpler
gen = provider.objectIdGeneratorInstance(accessor, objectIdInfo);
oiw = ObjectIdWriter.construct(idType, objectIdInfo.getPropertyName(), gen,
objectIdInfo.getAlwaysAsId());
}
}
// Or change Filter Id in use?
Object filterId = intr.findFilterId(accessor);
if (filterId != null) {
// but only consider case of adding a new filter id (no removal via annotation)
if (_propertyFilterId == null || !filterId.equals(_propertyFilterId)) {
newFilterId = filterId;
}
}
}
// either way, need to resolve serializer:
BeanSerializerBase contextual = this;
if (oiw != null) {
JsonSerializer<?> ser = provider.findValueSerializer(oiw.idType, property);
oiw = oiw.withSerializer(ser);
if (oiw != _objectIdWriter) {
contextual = contextual.withObjectIdWriter(oiw);
}
}
// And possibly add more properties to ignore
if (ignorals != null && ignorals.length != 0) {
contextual = contextual.withIgnorals(ignorals);
}
if (newFilterId != null) {
contextual = contextual.withFilterId(newFilterId);
}
if (shape == null) {
shape = _serializationShape;
}
if (shape == JsonFormat.Shape.ARRAY) {
return contextual.asArraySerializer();
}
return contextual;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public Iterator<PropertyWriter> properties() {
return Arrays.<PropertyWriter>asList(_props).iterator();
}
/*
/**********************************************************
/* Partial JsonSerializer implementation
/**********************************************************
*/
@Override
public boolean usesObjectId() {
return (_objectIdWriter != null);
}
// Main serialization method left unimplemented
@Override
public abstract void serialize(Object bean, JsonGenerator gen, SerializerProvider provider)
throws IOException;
// Type-info-augmented case implemented as it does not usually differ between impls
@
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>;
}
}
/**
* Enumeration type with sub-classes per value.
*/
protected enum EnumWithSubClass {
A { @Override public void foobar() { } }
,B { @Override public void foobar() { } }
;
public abstract void foobar();
}
public enum ABC { A, B, C; }
protected BaseMapTest() { super(); }
/*
/**********************************************************
/* Additional assert methods
/**********************************************************
*/
private final static ObjectMapper SHARED_MAPPER = new ObjectMapper();
protected ObjectMapper objectMapper() {
return SHARED_MAPPER;
}
protected ObjectWriter objectWriter() {
return SHARED_MAPPER.writer();
}
protected ObjectReader objectReader() {
return SHARED_MAPPER.reader();
}
protected ObjectReader objectReader(Class<?> cls) {
return SHARED_MAPPER.readerFor(cls);
}
/*
/**********************************************************
/* Additional assert methods
/**********************************************************
*/
protected void assertEquals(int[] exp, int[] act)
{
assertArrayEquals(exp, act);
}
/**
* Helper method for verifying 3 basic cookie cutter cases;
* identity comparison (true), and against null (false),
* or object of different type (false)
*/
protected void assertStandardEquals(Object o)
{
assertTrue(o.equals(o));
assertFalse(o.equals(null));
assertFalse(o.equals(SINGLETON_OBJECT));
// just for fun, let's also call hash code...
o.hashCode();
}
/*
/**********************************************************
/* Helper methods, serialization
/**********************************************************
*/
@SuppressWarnings("unchecked")
protected Map<String,Object> writeAndMap(ObjectMapper m, Object value)
throws IOException
{
String str = m.writeValueAsString(value);
return (Map<String,Object>) m.readValue(str, Map.class);
}
protected String serializeAsString(ObjectMapper m, Object value)
throws IOException
{
return m.writeValueAsString(value);
}
protected String serializeAsString(Object value)
throws IOException
{
return serializeAsString(SHARED_MAPPER, value);
}
protected String asJSONObjectValueString(Object... args)
throws IOException
{
return asJSONObjectValueString(SHARED_
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 64-bit integer values.
*/
public class LongNode
extends NumericNode
{
protected final long _value;
/*
************************************************
* Construction
************************************************
*/
public LongNode(long v) { _value = v; }
public static LongNode valueOf(long l) { return new LongNode(l); }
/*
************************************************
* Overrridden JsonNode methods
************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.LONG; }
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isLong() { return true; }
@Override public boolean canConvertToInt() {
return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
}
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Long.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return (int) _value; }
@Override
public long longValue() { return _value; }
@Override
public float floatValue() { return _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value != 0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof LongNode) {
return ((LongNode) o)._value == _value;
}
return false;
}
@Override
public int hashCode() {
return ((int) _value) ^ (int) (_value >> 32);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> }
@Override
public int containedTypeCount() { return 1; }
@Override
public JavaType containedType(int index) {
return (index == 0) ? _componentType : null;
}
@Override
public StringBuilder getGenericSignature(StringBuilder sb) {
sb.append('[');
return _componentType.getGenericSignature(sb);
}
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
sb.append('[');
return _componentType.getErasedSignature(sb);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public String toString()
{
return "[array type, component type: "+_componentType+"]";
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ArrayType other = (ArrayType) o;
return _componentType.equals(other._componentType);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains a text value.
*/
public class TextNode
extends ValueNode
{
final static TextNode EMPTY_STRING_NODE = new TextNode("");
protected final String _value;
public TextNode(String v) { _value = v; }
/**
* Factory method that should be used to construct instances.
* For some common cases, can reuse canonical instances: currently
* this is the case for empty Strings, in future possible for
* others as well. If null is passed, will return null.
*
* @return Resulting {@link TextNode} object, if <b>v</b>
* is NOT null; null if it is.
*/
public static TextNode valueOf(String v)
{
if (v == null) {
return null;
}
if (v.length() == 0) {
return EMPTY_STRING_NODE;
}
return new TextNode(v);
}
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.STRING;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_STRING; }
@Override
public String textValue() {
return _value;
}
/**
* Method for accessing textual contents assuming they were
* base64 encoded; if so, they are decoded and resulting binary
* data is returned.
*/
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
{
@SuppressWarnings("resource")
ByteArrayBuilder builder = new ByteArrayBuilder(100);
final String str = _value;
int ptr = 0;
int len = str.length();
main_loop:
while (ptr < len) {
// first, we'll skip preceding white space, if any
char ch;
do {
ch = str.charAt(ptr++);
if (ptr >= len) {
break
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>;
// fourth and last base64 char; can be padding, but not ws
if (ptr >= len) {
// but as per [JACKSON-631] can be end-of-input, iff not using padding
if (!b64variant.usesPadding()) {
decodedData >>= 2;
builder.appendTwoBytes(decodedData);
break;
}
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
if (bits != Base64Variant.BASE64_VALUE_PADDING) {
_reportInvalidBase64(b64variant, ch, 3);
}
decodedData >>= 2;
builder.appendTwoBytes(decodedData);
} else {
// otherwise, our triple is now complete
decodedData = (decodedData << 6) | bits;
builder.appendThreeBytes(decodedData);
}
}
return builder.toByteArray();
}
@Override
public byte[] binaryValue() throws IOException {
return getBinaryValue(Base64Variants.getDefaultVariant());
}
/*
/**********************************************************
/* General type coercions
/**********************************************************
*/
@Override
public String asText() {
return _value;
}
@Override
public String asText(String defaultValue) {
return (_value == null) ? defaultValue : _value;
}
// note: neither fast nor elegant, but these work for now:
@Override
public boolean asBoolean(boolean defaultValue) {
if (_value != null) {
String v = _value.trim();
if ("true".equals(v)) {
return true;
}
if ("false".equals(v)) {
return false;
}
}
return defaultValue;
}
@Override
public int asInt(int defaultValue) {
return NumberInput.parseAsInt(_value, defaultValue);
}
@Override
public long asLong(long defaultValue) {
return NumberInput.parseAsLong(_value, defaultValue);
}
@Override
public double asDouble(double defaultValue) {
return NumberInput.parseAsDouble(_value, defaultValue);
}
/*
/**********************************************************
/* Serialization
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> /**********************************************************
*/
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider) throws IOException
{
if (_value == null) {
jg.writeNull();
} else {
jg.writeString(_value);
}
}
/*
/**********************************************************
/* Overridden standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof TextNode) {
return ((TextNode) o)._value.equals(_value);
}
return false;
}
@Override
public int hashCode() { return _value.hashCode(); }
/**
* Different from other values, Strings need quoting
*/
@Override
public String toString()
{
int len = _value.length();
len = len + 2 + (len >> 4);
StringBuilder sb = new StringBuilder(len);
appendQuoted(sb, _value);
return sb.toString();
}
protected static void appendQuoted(StringBuilder sb, String content)
{
sb.append('"');
CharTypes.appendQuoted(sb, content);
sb.append('"');
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected void _reportInvalidBase64(Base64Variant b64variant, char ch, int bindex)
throws JsonParseException
{
_reportInvalidBase64(b64variant, ch, bindex, null);
}
/**
* @param bindex Relative index within base64 character unit; between 0
* and 3 (as unit has exactly 4 characters)
*/
protected void _reportInvalidBase64(Base64Variant b64variant, char ch, int bindex, String msg)
throws JsonParseException
{
String base;
if (ch <= ' ') {
base = "Illegal white space character (code 0x"+Integer.toHexString(ch)+") as character #"+(bindex+1)+" of 4-char base64 unit: can only used between units";
} else if (b64variant.usesPaddingChar(ch)) {
base = "Unexpected padding character ('"+b64variant.getPaddingChar()+"') as
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> passed in; returned to allow
* call chaining
*/
public abstract StringBuilder getGenericSignature(StringBuilder sb);
/**
* Method for accessing signature without generic
* type information, in form compatible with all versions
* of JVM, and specifically used for type descriptions
* when generating byte code.
*/
public String getErasedSignature() {
StringBuilder sb = new StringBuilder(40);
getErasedSignature(sb);
return sb.toString();
}
/**
* Method for accessing signature without generic
* type information, in form compatible with all versions
* of JVM, and specifically used for type descriptions
* when generating byte code.
*
* @param sb StringBuilder to append signature to
*
* @return StringBuilder that was passed in; returned to allow
* call chaining
*/
public abstract StringBuilder getErasedSignature(StringBuilder sb);
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected void _assertSubclass(Class<?> subclass, Class<?> superClass) {
if (!_class.isAssignableFrom(subclass)) {
throw new IllegalArgumentException("Class "+subclass.getName()+" is not assignable to "+_class.getName());
}
}
/*
/**********************************************************
/* Standard methods; let's make them abstract to force override
/**********************************************************
*/
@Override
public abstract String toString();
@Override
public abstract boolean equals(Object o);
@Override
public final int hashCode() { return _hash; }
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 16-bit integer values.
*/
public class ShortNode
extends NumericNode
{
protected final short _value;
/*
************************************************
* Construction
************************************************
*/
public ShortNode(short v) { _value = v; }
public static ShortNode valueOf(short l) { return new ShortNode(l); }
/*
************************************************
* Overridden JsonNode methods
************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.INT; } // should be SHORT
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isShort() { return true; }
@Override public boolean canConvertToInt() { return true; }
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Short.valueOf(_value);
}
@Override
public short shortValue() { return _value; }
@Override
public int intValue() { return _value; }
@Override
public long longValue() { return _value; }
@Override
public float floatValue() { return _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
@Override
public String asText() {
return NumberOutput.toString(_value);
}
@Override
public boolean asBoolean(boolean defaultValue) {
return _value != 0;
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>() throws IOException, JsonParseException
{
if (_currToken == JsonToken.START_OBJECT) {
_startContainer = false;
_currToken = JsonToken.END_OBJECT;
} else if (_currToken == JsonToken.START_ARRAY) {
_startContainer = false;
_currToken = JsonToken.END_ARRAY;
}
return this;
}
@Override
public boolean isClosed() {
return _closed;
}
/*
/**********************************************************
/* Public API, token accessors
/**********************************************************
*/
@Override
public String getCurrentName() {
return (_nodeCursor == null) ? null : _nodeCursor.getCurrentName();
}
@Override
public void overrideCurrentName(String name)
{
if (_nodeCursor != null) {
_nodeCursor.overrideCurrentName(name);
}
}
@Override
public JsonStreamContext getParsingContext() {
return _nodeCursor;
}
@Override
public JsonLocation getTokenLocation() {
return JsonLocation.NA;
}
@Override
public JsonLocation getCurrentLocation() {
return JsonLocation.NA;
}
/*
/**********************************************************
/* Public API, access to textual content
/**********************************************************
*/
@Override
public String getText()
{
if (_closed) {
return null;
}
// need to separate handling a bit...
switch (_currToken) {
case FIELD_NAME:
return _nodeCursor.getCurrentName();
case VALUE_STRING:
return currentNode().textValue();
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return String.valueOf(currentNode().numberValue());
case VALUE_EMBEDDED_OBJECT:
JsonNode n = currentNode();
if (n != null && n.isBinary()) {
// this will convert it to base64
return n.asText();
}
default:
return (_currToken == null) ? null : _currToken.asString();
}
}
@Override
public char[] getTextCharacters() throws IOException, JsonParseException {
return getText().toCharArray();
}
@Override
public int getTextLength() throws IOException, JsonParseException {
return getText().length();
}
@Override
public int getTextOffset() throws IOException, JsonParseException {
return 0;
}
@
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> value;
_isTyped = key.isTyped();
_class = key.getRawType();
_type = key.getType();
}
public boolean matchesTyped(Class<?> key) {
return (_class == key) && _isTyped;
}
public boolean matchesUntyped(Class<?> key) {
return (_class == key) && !_isTyped;
}
public boolean matchesTyped(JavaType key) {
return _isTyped && key.equals(_type);
}
public boolean matchesUntyped(JavaType key) {
return !_isTyped && key.equals(_type);
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* Simple general purpose serializer, useful for any
* type for which {@link Object#toString} returns the desired JSON
* value.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class ToStringSerializer
extends StdSerializer<Object>
{
/**
* Singleton instance to use.
*/
public final static ToStringSerializer instance = new ToStringSerializer();
/**
*<p>
* Note: usually you should NOT create new instances, but instead use
* {@link #instance} which is stateless and fully thread-safe. However,
* there are cases where constructor is needed; for example,
* when using explicit serializer annotations like
* {@link com.fasterxml.jackson.databind.annotation.JsonSerialize#using}.
*/
public ToStringSerializer() { super(Object.class); }
/**
* Sometimes it may actually make sense to retain actual handled type, so...
*
* @since 2.5
*/
public ToStringSerializer(Class<?> handledType) {
super(handledType, false);
}
@Override
@Deprecated
public boolean isEmpty(Object value) {
return isEmpty(null, value);
}
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
if (value == null) {
return true;
}
String str = value.toString();
return str.isEmpty();
}
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
gen.writeString(value.toString());
}
/* 01-Mar-2011, tatu: We were serializing as "raw" String; but
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* <code>JsonNode</code> implementation for efficiently containing 32-bit
* `float` values.
*
* @since 2.2
*/
public class FloatNode extends NumericNode
{
protected final float _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public FloatNode(float v) { _value = v; }
public static FloatNode valueOf(float v) { return new FloatNode(v); }
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_FLOAT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.FLOAT; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isFloatingPointNumber() { return true; }
@Override
public boolean isFloat() { return true; }
@Override public boolean canConvertToInt() {
return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
}
@Override public boolean canConvertToLong() {
return (_value >= Long.MIN_VALUE && _value <= Long.MAX_VALUE);
}
@Override
public Number numberValue() {
return Float.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return (int) _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() {
return decimalValue().toBigInteger();
}
@Override
public String asText() {
// As per [jackson-databind#707
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>]
// return NumberOutput.toString(_value);
// TODO: in 2.7, call `NumberOutput.toString (added in 2.6); not yet for backwards compat
return Float.toString(_value);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider) throws IOException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof FloatNode) {
// We must account for NaNs: NaN does not equal NaN, therefore we have
// to use Double.compare().
final float otherValue = ((FloatNode) o)._value;
return Float.compare(_value, otherValue) == 0;
}
return false;
}
@Override
public int hashCode() {
return Float.floatToIntBits(_value);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> First: if we have a property, may have property-annotation overrides
if (property != null) {
AnnotatedMember m = property.getMember();
final AnnotationIntrospector intr = provider.getAnnotationIntrospector();
if (m != null) {
Object serDef = intr.findContentSerializer(m);
if (serDef != null) {
ser = provider.serializerInstance(m, serDef);
}
}
JsonFormat.Value format = property.findFormatOverrides(intr);
if (format != null) {
unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
}
}
if (ser == null) {
ser = _elementSerializer;
}
// #124: May have a content converter
ser = findConvertingContentSerializer(provider, property, ser);
if (ser == null) {
// 30-Sep-2012, tatu: One more thing -- if explicit content type is annotated,
// we can consider it a static case as well.
if (_elementType != null) {
if (_staticTyping || hasContentTypeAnnotation(provider, property)) {
ser = provider.findValueSerializer(_elementType, property);
}
}
} else {
ser = provider.handleSecondaryContextualization(ser, property);
}
return withResolved(property, vts, ser, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _elementType;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _elementSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, Object[] value) {
return (value == null) || (value.length == 0);
}
@Override
public boolean hasSingleElement(Object[] value) {
return (value.length == 1);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(Serialization
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
/**
* Numeric node that contains values that do not fit in simple
* integer (int, long) or floating point (double) values.
*/
public class DecimalNode
extends NumericNode
{
public static final DecimalNode ZERO = new DecimalNode(BigDecimal.ZERO);
private final static BigDecimal MIN_INTEGER = BigDecimal.valueOf(Integer.MIN_VALUE);
private final static BigDecimal MAX_INTEGER = BigDecimal.valueOf(Integer.MAX_VALUE);
private final static BigDecimal MIN_LONG = BigDecimal.valueOf(Long.MIN_VALUE);
private final static BigDecimal MAX_LONG = BigDecimal.valueOf(Long.MAX_VALUE);
final protected BigDecimal _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public DecimalNode(BigDecimal v) { _value = v; }
public static DecimalNode valueOf(BigDecimal d) { return new DecimalNode(d); }
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_FLOAT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.BIG_DECIMAL; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isFloatingPointNumber() { return true; }
@Override
public boolean isBigDecimal() { return true; }
@Override public boolean canConvertToInt() {
return (_value.compareTo(MIN_INTEGER) >= 0) && (_value.compareTo(MAX_INTEGER) <= 0);
}
@Override public boolean canConvertToLong() {
return (_value.compareTo(MIN_LONG) >= 0) && (_value.compareTo(MAX_LONG) <= 0);
}
@Override
public Number numberValue() { return _value; }
@Override
public short shortValue() { return _value.shortValue(); }
@Override
public int intValue() { return _value.intValue(); }
@Override
public long longValue() { return _value.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>longValue(); }
@Override
public BigInteger bigIntegerValue() { return _value.toBigInteger(); }
@Override
public float floatValue() { return _value.floatValue(); }
@Override
public double doubleValue() { return _value.doubleValue(); }
@Override
public BigDecimal decimalValue() { return _value; }
@Override
public String asText() {
return _value.toString();
}
@Override
public final void serialize(JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
// 07-Jul-2013, tatu: Should be handled by propagating setting to JsonGenerator
// so this should not be needed:
/*
if (provider.isEnabled(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN)) {
if (!(jgen instanceof TokenBuffer)) { // [Issue#232]
jgen.writeNumber(((BigDecimal) _value).toPlainString());
return;
}
}
*/
jgen.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof DecimalNode) {
return ((DecimalNode) o)._value.compareTo(_value) == 0;
}
return false;
}
@Override
public int hashCode() { return Double.valueOf(doubleValue()).hashCode(); }
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.type;
/**
* Key class, used as an efficient and accurate key
* for locating per-class values, such as
* {@link com.fasterxml.jackson.databind.JsonSerializer}s.
*<p>
* The reason for having a separate key class instead of
* directly using {@link Class} as key is mostly
* to allow for redefining <code>hashCode</code> method --
* for some strange reason, {@link Class} does not
* redefine {@link Object#hashCode} and thus uses identity
* hash, which is pretty slow. This makes key access using
* {@link Class} unnecessarily slow.
*<p>
* Note: since class is not strictly immutable, caller must
* know what it is doing, if changing field values.
*/
public final class ClassKey
implements Comparable<ClassKey>,
java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L;
private String _className;
private Class<?> _class;
/**
* Let's cache hash code straight away, since we are
* almost certain to need it.
*/
private int _hashCode;
public ClassKey()
{
_class = null;
_className = null;
_hashCode = 0;
}
public ClassKey(Class<?> clz)
{
_class = clz;
_className = clz.getName();
_hashCode = _className.hashCode();
}
public void reset(Class<?> clz)
{
_class = clz;
_className = clz.getName();
_hashCode = _className.hashCode();
}
/*
/**********************************************************
/* Comparable
/**********************************************************
*/
@Override
public int compareTo(ClassKey other)
{
// Just need to sort by name, ok to collide (unless used in TreeMap/Set!)
return _className.compareTo(other._className);
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
ClassKey other = (ClassKey)
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>ARRAY: // invalid
// case JsonTokenId.ID_END_OBJECT: // invalid
default:
}
throw ctxt.mappingException(Object.class);
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException
{
switch (p.getCurrentTokenId()) {
// First: does it look like we had type id wrapping of some kind?
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
/* Output can be as JSON Object, Array or scalar: no way to know
* a this point:
*/
return typeDeserializer.deserializeTypedFromAny(p, ctxt);
case JsonTokenId.ID_EMBEDDED_OBJECT:
return p.getEmbeddedObject();
/* Otherwise we probably got a "native" type (ones that map
* naturally and thus do not need or use type ids)
*/
case JsonTokenId.ID_STRING:
if (_stringDeserializer != null) {
return _stringDeserializer.deserialize(p, ctxt);
}
return p.getText();
case JsonTokenId.ID_NUMBER_INT:
if (_numberDeserializer != null) {
return _numberDeserializer.deserialize(p, ctxt);
}
// May need coercion to "bigger" types:
if (ctxt.hasSomeOfFeatures(F_MASK_INT_COERCIONS)) {
return _coerceIntegral(p, ctxt);
}
return p.getNumberValue(); // should be optimal, whatever it is
case JsonTokenId.ID_NUMBER_FLOAT:
if (_numberDeserializer != null) {
return _numberDeserializer.deserialize(p, ctxt);
}
// For [JACKSON-72], see above
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return p.getDecimalValue();
}
return Double.valueOf(p.getDoubleValue());
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_NULL: // should not get this far really but...
return null;
default:
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>TokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return p.getDecimalValue();
}
return Double.valueOf(p.getDoubleValue());
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_NULL: // should not get this but...
return null;
//case JsonTokenId.ID_END_ARRAY: // invalid
//case JsonTokenId.ID_END_OBJECT: // invalid
default:
throw ctxt.mappingException(Object.class);
}
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException
{
switch (jp.getCurrentTokenId()) {
case JsonTokenId.ID_START_ARRAY:
case JsonTokenId.ID_START_OBJECT:
case JsonTokenId.ID_FIELD_NAME:
return typeDeserializer.deserializeTypedFromAny(jp, ctxt);
case JsonTokenId.ID_STRING:
return jp.getText();
case JsonTokenId.ID_NUMBER_INT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) {
return jp.getBigIntegerValue();
}
return jp.getNumberValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return jp.getDecimalValue();
}
return Double.valueOf(jp.getDoubleValue());
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_EMBEDDED_OBJECT:
return jp.getEmbeddedObject();
case JsonTokenId.ID_NULL: // should not get this far really but...
return null;
default:
throw ctxt.mappingException(Object.class);
}
}
protected Object mapArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
Object value = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.reflect.Method;
import java.util.*;
/**
* Simple helper class used to keep track of collection of
* {@link AnnotatedMethod}s, accessible by lookup. Lookup
* is usually needed for augmenting and overriding annotations.
*/
public final class AnnotatedMethodMap
implements Iterable<AnnotatedMethod>
{
protected LinkedHashMap<MemberKey,AnnotatedMethod> _methods;
public AnnotatedMethodMap() { }
/**
* Method called to add specified annotated method in the Map.
*/
public void add(AnnotatedMethod am)
{
if (_methods == null) {
_methods = new LinkedHashMap<MemberKey,AnnotatedMethod>();
}
_methods.put(new MemberKey(am.getAnnotated()), am);
}
/**
* Method called to remove specified method, assuming
* it exists in the Map
*/
public AnnotatedMethod remove(AnnotatedMethod am)
{
return remove(am.getAnnotated());
}
public AnnotatedMethod remove(Method m)
{
if (_methods != null) {
return _methods.remove(new MemberKey(m));
}
return null;
}
public boolean isEmpty() {
return (_methods == null || _methods.size() == 0);
}
public int size() {
return (_methods == null) ? 0 : _methods.size();
}
public AnnotatedMethod find(String name, Class<?>[] paramTypes)
{
if (_methods == null) {
return null;
}
return _methods.get(new MemberKey(name, paramTypes));
}
public AnnotatedMethod find(Method m)
{
if (_methods == null) {
return null;
}
return _methods.get(new MemberKey(m));
}
/*
/**********************************************************
/* Iterable implementation (for iterating over values)
/**********************************************************
*/
@Override
public Iterator<AnnotatedMethod> iterator()
{
if (_methods != null) {
return _methods.values().iterator();
}
List<AnnotatedMethod> empty = Collections.emptyList();
return empty.iterator();
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>, property, ser, unwrapSingle);
}
/*
/**********************************************************
/* Simple accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return VALUE_TYPE;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _elementSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, String[] value) {
return (value == null) || (value.length == 0);
}
@Override
public boolean hasSingleElement(String[] value) {
return (value.length == 1);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(String[] value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.length;
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(String[] value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsSlow(value, gen, provider, _elementSerializer);
return;
}
for (int i = 0; i < len; ++i) {
String str = value[i];
if (str == null) {
gen.writeNull();
} else {
gen.writeString(value[i]);
}
}
}
private void serializeContentsSlow(String[] value, JsonGenerator gen, SerializerProvider provider, JsonSerializer<Object> ser)
throws IOException
{
for (int i = 0, len = value.length; i < len; ++i) {
String str = value[i];
if (str == null) {
provider.defaultSerializeNull(gen);
} else {
ser.serialize(value[i], gen, provider);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>new(NameTransformer transformer, SerializedString newName)
{
return new UnwrappingBeanPropertyWriter(this, transformer, newName);
}
/*
/**********************************************************
/* Overrides, public methods
/**********************************************************
*/
@Override
public boolean isUnwrapping() {
return true;
}
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
final Object value = get(bean);
if (value == null) {
// Hmmh. I assume we MUST pretty much suppress nulls, since we
// can't really unwrap them...
return;
}
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap map = _dynamicSerializers;
ser = map.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(map, cls, prov);
}
}
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
return;
}
} else if (_suppressableValue.equals(value)) {
return;
}
}
// For non-nulls, first: simple check for direct cycles
if (value == bean) {
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
// note: must verify we are using unwrapping serializer; if not, will write field name
if (!ser.isUnwrappingSerializer()) {
gen.writeFieldName(_name);
}
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
// need to override as we must get unwrapping instance...
@Override
public void assignSerializer(JsonSerializer<Object> ser)
{
super.assignSerializer(ser);
if (_serializer != null) {
NameTransformer t = _nameTransformer;
if (_serializer.isUnwrappingSerializer()) {
t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) _serializer)._nameTransformer);
}
_serializer = _serializer.unwrappingSerializer
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> if (t == null) {
/* [JACKSON-546] Throw mapping exception, since it's failure to map,
* not an actual parsing problem
*/
throw JsonMappingException.from(p, "No content to map due to end-of-input");
}
}
return t;
}
protected Object _unwrapAndDeserialize(JsonParser p, DeserializationContext ctxt,
DeserializationConfig config,
JavaType rootType, JsonDeserializer<Object> deser)
throws IOException
{
PropertyName expRootName = config.findRootName(rootType);
// 12-Jun-2015, tatu: Should try to support namespaces etc but...
String expSimpleName = expRootName.getSimpleName();
if (p.getCurrentToken() != JsonToken.START_OBJECT) {
throw JsonMappingException.from(p, "Current token not START_OBJECT (needed to unwrap root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
if (p.nextToken() != JsonToken.FIELD_NAME) {
throw JsonMappingException.from(p, "Current token not FIELD_NAME (to contain expected root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
String actualName = p.getCurrentName();
if (!expSimpleName.equals(actualName)) {
throw JsonMappingException.from(p, "Root name '"+actualName+"' does not match expected ('"
+expSimpleName+"') for type "+rootType);
}
// ok, then move to value itself....
p.nextToken();
Object result = deser.deserialize(p, ctxt);
// and last, verify that we now get matching END_OBJECT
if (p.nextToken() != JsonToken.END_OBJECT) {
throw JsonMappingException.from(p, "Current token not END_OBJECT (to match wrapper object with root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
return result;
}
/*
/**********************************************************
/* Internal methods, other
/**********************************************************
*/
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt,
JavaType valueType)
throws JsonMapping
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>015, tatu: As per [databind#677], need to allow explicit naming.
// Unfortunately can not quite use standard AnnotatedClass here (due to various
// reasons, including odd representation JVM uses); has to do for now
try {
// We know that values are actually static fields with matching name so:
Field f = value.getClass().getField(value.name());
if (f != null) {
JsonProperty prop = f.getAnnotation(JsonProperty.class);
String n = prop.value();
if (n != null && !n.isEmpty()) {
return n;
}
}
} catch (Exception e) {
// no such field, or access; neither which we can do much about
}
return value.name();
}
/*
/**********************************************************
/* General class annotations
/**********************************************************
*/
@Override
public PropertyName findRootName(AnnotatedClass ac)
{
JsonRootName ann = _findAnnotation(ac, JsonRootName.class);
if (ann == null) {
return null;
}
String ns = ann.namespace();
if (ns != null && ns.length() == 0) {
ns = null;
}
return PropertyName.construct(ann.value(), ns);
}
@Override
@Deprecated // since 2.6, remove from 2.7 or later
public String[] findPropertiesToIgnore(Annotated ac) {
JsonIgnoreProperties ignore = _findAnnotation(ac, JsonIgnoreProperties.class);
return (ignore == null) ? null : ignore.value();
}
@Override // since 2.6
public String[] findPropertiesToIgnore(Annotated ac, boolean forSerialization) {
JsonIgnoreProperties ignore = _findAnnotation(ac, JsonIgnoreProperties.class);
if (ignore == null) {
return null;
}
// 13-May-2015, tatu: As per [databind#95], allow read-only/write-only props
if (forSerialization) {
if (ignore.allowGetters()) {
return null;
}
} else {
if (ignore.allowSetters()) {
return null;
}
}
return ignore.value();
}
@Override
public Boolean findIgnoreUnknownProperties(AnnotatedClass ac
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
return ann.required();
}
return null;
}
@Override
public JsonProperty.Access findPropertyAccess(Annotated m) {
JsonProperty ann = _findAnnotation(m, JsonProperty.class);
if (ann != null) {
return ann.access();
}
return null;
}
@Override
public String findPropertyDescription(Annotated ann) {
JsonPropertyDescription desc = _findAnnotation(ann, JsonPropertyDescription.class);
return (desc == null) ? null : desc.value();
}
@Override
public Integer findPropertyIndex(Annotated ann) {
JsonProperty prop = _findAnnotation(ann, JsonProperty.class);
if (prop != null) {
int ix = prop.index();
if (ix != JsonProperty.INDEX_UNKNOWN) {
return Integer.valueOf(ix);
}
}
return null;
}
@Override
public String findPropertyDefaultValue(Annotated ann) {
JsonProperty prop = _findAnnotation(ann, JsonProperty.class);
if (prop == null) {
return null;
}
String str = prop.defaultValue();
// Since annotations do not allow nulls, need to assume empty means "none"
return str.isEmpty() ? null : str;
}
@Override
public JsonFormat.Value findFormat(Annotated ann) {
JsonFormat f = _findAnnotation(ann, JsonFormat.class);
return (f == null) ? null : new JsonFormat.Value(f);
}
@Override
public ReferenceProperty findReferenceType(AnnotatedMember member)
{
JsonManagedReference ref1 = _findAnnotation(member, JsonManagedReference.class);
if (ref1 != null) {
return AnnotationIntrospector.ReferenceProperty.managed(ref1.value());
}
JsonBackReference ref2 = _findAnnotation(member, JsonBackReference.class);
if (ref2 != null) {
return AnnotationIntrospector.ReferenceProperty.back(ref2.value());
}
return null;
}
@Override
public NameTransformer findUnwrappingNameTransformer(AnnotatedMember member)
{
JsonUnwrapped ann = _findAnnotation(member, JsonUnwrapped.class);
// if not enabled, just means annotation is not enabled; not necessarily
// that unwrapping should not be done (
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> protected Class<?> _classIfExplicit(Class<?> cls) {
if (cls == null || ClassUtil.isBogusClass(cls)) {
return null;
}
return cls;
}
protected Class<?> _classIfExplicit(Class<?> cls, Class<?> implicit) {
cls = _classIfExplicit(cls);
return (cls == null || cls == implicit) ? null : cls;
}
protected PropertyName _propertyName(String localName, String namespace) {
if (localName.isEmpty()) {
return PropertyName.USE_DEFAULT;
}
if (namespace == null || namespace.isEmpty()) {
return PropertyName.construct(localName);
}
return PropertyName.construct(localName, namespace);
}
/**
* Helper method called to construct and initialize instance of {@link TypeResolverBuilder}
* if given annotated element indicates one is needed.
*/
@SuppressWarnings("deprecation")
protected TypeResolverBuilder<?> _findTypeResolver(MapperConfig<?> config,
Annotated ann, JavaType baseType)
{
// First: maybe we have explicit type resolver?
TypeResolverBuilder<?> b;
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class);
JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class);
if (resAnn != null) {
if (info == null) {
return null;
}
/* let's not try to force access override (would need to pass
* settings through if we did, since that's not doable on some
* platforms)
*/
b = config.typeResolverBuilderInstance(ann, resAnn.value());
} else { // if not, use standard one, if indicated by annotations
if (info == null) {
return null;
}
// bit special; must return 'marker' to block use of default typing:
if (info.use() == JsonTypeInfo.Id.NONE) {
return _constructNoTypeResolverBuilder();
}
b = _constructStdTypeResolverBuilder();
}
// Does it define a custom type id resolver?
JsonTypeIdResolver idResInfo = _findAnnotation(ann, JsonTypeIdResolver.class);
TypeIdResolver idRes = (idResInfo == null) ? null
: config.typeIdResolverInstance(ann, idResInfo.value());
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> /**
* Method that may be called on instance to determine if it is considered
* "empty" for purposes of serialization filtering or not.
*/
public boolean isEmpty(SerializerProvider serializers) {
return false;
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> = base._accessorMethod;
_field = base._field;
_serializer = base._serializer;
_nullSerializer = base._nullSerializer;
if (base._internalSettings != null) {
_internalSettings = new HashMap<Object,Object>(base._internalSettings);
}
_cfgSerializationType = base._cfgSerializationType;
_dynamicSerializers = base._dynamicSerializers;
_suppressNulls = base._suppressNulls;
_suppressableValue = base._suppressableValue;
_includeInViews = base._includeInViews;
_typeSerializer = base._typeSerializer;
_nonTrivialBaseType = base._nonTrivialBaseType;
_metadata = base._metadata;
}
public BeanPropertyWriter rename(NameTransformer transformer) {
String newName = transformer.transform(_name.getValue());
if (newName.equals(_name.toString())) {
return this;
}
return _new(PropertyName.construct(newName));
}
/**
* Overridable factory method used by sub-classes
*
* @since 2.6.0
*/
protected BeanPropertyWriter _new(PropertyName newName) {
return new BeanPropertyWriter(this, newName);
}
/**
* Method called to set, reset or clear the configured type serializer
* for property.
*
* @since 2.6
*/
public void assignTypeSerializer(TypeSerializer typeSer) {
_typeSerializer = typeSer;
}
/**
* Method called to assign value serializer for property
*
* @since 2.0
*/
public void assignSerializer(JsonSerializer<Object> ser) {
// may need to disable check in future?
if (_serializer != null && _serializer != ser) {
throw new IllegalStateException("Can not override serializer");
}
_serializer = ser;
}
/**
* Method called to assign null value serializer for property
*
* @since 2.0
*/
public void assignNullSerializer(JsonSerializer<Object> nullSer) {
// may need to disable check in future?
if (_nullSerializer != null && _nullSerializer != nullSer) {
throw new IllegalStateException("Can not override null serializer");
}
_nullSerializer = nullSer;
}
/**
* Method called create an instance that handles details of unwrapping
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>/or suffix (or in some cases, just removal of wrapper name).
*<p>
* Default implementation simply returns false.
*
* @since 2.3
*/
public boolean isUnwrapping() { return false; }
public boolean willSuppressNulls() { return _suppressNulls; }
/**
* Method called to check to see if this property has a name that would
* conflict with a given name.
*
* @since 2.6
*/
public boolean wouldConflictWithName(PropertyName name) {
if (_wrapperName != null) {
return _wrapperName.equals(name);
}
// Bit convoluted since our support for namespaces is spotty but:
return name.hasSimpleName(_name.getValue())
&& !name.hasNamespace();
}
// Needed by BeanSerializer#getSchema
public JsonSerializer<Object> getSerializer() { return _serializer; }
public JavaType getSerializationType() { return _cfgSerializationType; }
public Class<?> getRawSerializationType() {
return (_cfgSerializationType == null) ? null : _cfgSerializationType.getRawClass();
}
public Class<?> getPropertyType() {
return (_accessorMethod != null) ? _accessorMethod.getReturnType() : _field.getType();
}
/**
* Get the generic property type of this property writer.
*
* @return The property type, or null if not found.
*/
public Type getGenericPropertyType() {
if (_accessorMethod != null) {
return _accessorMethod.getGenericReturnType();
}
if (_field != null) {
return _field.getGenericType();
}
return null;
}
public Class<?>[] getViews() { return _includeInViews; }
/*
/**********************************************************
/* PropertyWriter methods (serialization)
/**********************************************************
*/
/**
* Method called to access property that this bean stands for, from
* within given bean, and to serialize it as a JSON Object field
* using appropriate serializer.
*/
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
// inlined 'get()'
final Object value = (_accessorMethod == null) ? _field.get(bean) : _accessorMethod.invoke(bean);
// Null handling is bit different, check
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> that first
if (value == null) {
if (_nullSerializer != null) {
gen.writeFieldName(_name);
_nullSerializer.serialize(null, gen, prov);
}
return;
}
// then find serializer to use
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap m = _dynamicSerializers;
ser = m.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(m, cls, prov);
}
}
// and then see if we must suppress certain values (default, empty)
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
return;
}
} else if (_suppressableValue.equals(value)) {
return;
}
}
// For non-nulls: simple check for direct cycles
if (value == bean) {
// three choices: exception; handled by call; or pass-through
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
gen.writeFieldName(_name);
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
/**
* Method called to indicate that serialization of a field was omitted
* due to filtering, in cases where backend data format does not allow
* basic omission.
*
* @since 2.3
*/
@Override
public void serializeAsOmittedField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
if (!gen.canOmitFields()) {
gen.writeOmittedField(_name.getValue());
}
}
/**
* Alternative to {@link #serializeAsField} that is used when a POJO
* is serialized as JSON Array; the difference is that no field names
* are written.
*
* @since 2.3
*/
@Override
public void serializeAsElement(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
// inlined 'get()'
final
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> Object value = (_accessorMethod == null) ? _field.get(bean) : _accessorMethod.invoke(bean);
if (value == null) { // nulls need specialized handling
if (_nullSerializer != null) {
_nullSerializer.serialize(null, gen, prov);
} else { // can NOT suppress entries in tabular output
gen.writeNull();
}
return;
}
// otherwise find serializer to use
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap map = _dynamicSerializers;
ser = map.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(map, cls, prov);
}
}
// and then see if we must suppress certain values (default, empty)
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) { // can NOT suppress entries in tabular output
serializeAsPlaceholder(bean, gen, prov);
return;
}
} else if (_suppressableValue.equals(value)) { // can NOT suppress entries in tabular output
serializeAsPlaceholder(bean, gen, prov);
return;
}
}
// For non-nulls: simple check for direct cycles
if (value == bean) {
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
/**
* Method called to serialize a placeholder used in tabular output when
* real value is not to be included (is filtered out), but when we need
* an entry so that field indexes will not be off. Typically this should
* output null or empty String, depending on datatype.
*
* @since 2.1
*/
@Override
public void serializeAsPlaceholder(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
if (_nullSerializer != null) {
_nullSerializer.serialize(null, gen, prov);
} else {
gen.writeNull();
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>findAndAddPrimarySerializer(t, provider, this);
} else {
result = map.findAndAddPrimarySerializer(type, provider, this);
}
// did we get a new map of serializers? If so, start using it
if (map != result.map) {
_dynamicSerializers = result.map;
}
return result.serializer;
}
/**
* Method that can be used to access value of the property this
* Object describes, from given bean instance.
*<p>
* Note: method is final as it should not need to be overridden -- rather,
* calling method(s) ({@link #serializeAsField}) should be overridden
* to change the behavior
*/
public final Object get(Object bean) throws Exception {
return (_accessorMethod == null) ? _field.get(bean) : _accessorMethod.invoke(bean);
}
/**
* Method called to handle a direct self-reference through this property.
* Method can choose to indicate an error by throwing {@link JsonMappingException};
* fully handle serialization (and return true); or indicate that it should be
* serialized normally (return false).
*<p>
* Default implementation will throw {@link JsonMappingException} if
* {@link SerializationFeature#FAIL_ON_SELF_REFERENCES} is enabled;
* or return <code>false</code> if it is disabled.
*
* @return True if method fully handled self-referential value; false if not (caller
* is to handle it) or {@link JsonMappingException} if there is no way handle it
*/
protected boolean _handleSelfReference(Object bean, JsonGenerator gen, SerializerProvider prov, JsonSerializer<?> ser)
throws JsonMappingException {
if (prov.isEnabled(SerializationFeature.FAIL_ON_SELF_REFERENCES)
&& !ser.usesObjectId()) {
// 05-Feb-2013, tatu: Usually a problem, but NOT if we are handling
// object id; this may be the case for BeanSerializers at least.
// 13-Feb-2014, tatu: another possible ok case: custom serializer (something
// OTHER than {@link BeanSerializerBase}
if (ser instanceof BeanSerializerBase) {
throw new JsonMappingException("Direct self
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* Abstract class that defines API used by {@link SerializerProvider}
* to obtain actual
* {@link JsonSerializer} instances from multiple distinct factories.
*/
public abstract class SerializerFactory
{
/*
/**********************************************************
/* Additional configuration methods
/**********************************************************
*/
/**
* Convenience method for creating a new factory instance with additional serializer
* provider; equivalent to calling
*<pre>
* withConfig(getConfig().withAdditionalSerializers(additional));
*</pre>
*/
public abstract SerializerFactory withAdditionalSerializers(Serializers additional);
public abstract SerializerFactory withAdditionalKeySerializers(Serializers additional);
/**
* Convenience method for creating a new factory instance with additional bean
* serializer modifier; equivalent to calling
*<pre>
* withConfig(getConfig().withSerializerModifier(modifier));
*</pre>
*/
public abstract SerializerFactory withSerializerModifier(BeanSerializerModifier modifier);
/*
/**********************************************************
/* Basic SerializerFactory API:
/**********************************************************
*/
/**
* Method called to create (or, for immutable serializers, reuse) a serializer for given type.
*
* @param prov Provider that needs to be used to resolve annotation-provided
* serializers (but NOT for others)
*
* @since 2.1 (earlier versions had method with different signature)
*/
public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov,
JavaType baseType)
throws JsonMappingException;
/**
* Method called to create a type information serializer for given base type,
* if one is needed. If not needed (no polymorphic handling configured), should
* return null.
*
* @param baseType Declared type to use as the base type for type information serializer
*
* @return Type serializer to use for the base type, if one is needed; null if not.
*/
public abstract TypeSerializer createTypeSerializer(SerializationConfig config,
JavaType baseType)
throws JsonMappingException;
/**
* Method called to create serializer to use for serializing JSON property names (which must
* be output as <code>JsonToken.FIELD_NAME</code>) for Map that has
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Specialized {@link JsonSerializer} to output {@link java.util.UUID}s.
* Beyond optimized access and writing of textual representation (which
* is the default handling in most cases), it will alternatively
* allow serialization using raw binary output (as 16-byte block)
* if underlying data format has efficient means to access that.
*/
@SuppressWarnings("serial")
public class UUIDSerializer
extends StdScalarSerializer<UUID>
{
final static char[] HEX_CHARS = "0123456789abcdef".toCharArray();
public UUIDSerializer() { super(UUID.class); }
@Override
@Deprecated // since 2.5
public boolean isEmpty(UUID value) {
return isEmpty(null, value);
}
@Override
public boolean isEmpty(SerializerProvider prov, UUID value)
{
if (value == null) {
return true;
}
// Null UUID is empty, so...
if (value.getLeastSignificantBits() == 0L
&& value.getMostSignificantBits() == 0L) {
return true;
}
return false;
}
@Override
public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
// First: perhaps we could serialize it as raw binary data?
if (gen.canWriteBinaryNatively()) {
/* 07-Dec-2013, tatu: One nasty case; that of TokenBuffer. While it can
* technically retain binary data, we do not want to do use binary
* with it, as that results in UUIDs getting converted to Base64 for
* most conversions.
*/
if (!(gen instanceof TokenBuffer)) {
gen.writeBinary(_asBytes(value));
return;
}
}
// UUID.toString() works ok functionally, but we can make it go much faster
// (by 4x with micro-benchmark)
final char[] ch = new
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> 'withAdditionalSerializers': can not instantiate subtype with "
+"additional serializer definitions");
}
return new BeanSerializerFactory(config);
}
@Override
protected Iterable<Serializers> customSerializers() {
return _factoryConfig.serializers();
}
/*
/**********************************************************
/* SerializerFactory impl
/**********************************************************
*/
/**
* Main serializer constructor method. We will have to be careful
* with respect to ordering of various method calls: essentially
* we want to reliably figure out which classes are standard types,
* and which are beans. The problem is that some bean Classes may
* implement standard interfaces (say, {@link java.lang.Iterable}.
*<p>
* Note: sub-classes may choose to complete replace implementation,
* if they want to alter priority of serializer lookups.
*/
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<Object> createSerializer(SerializerProvider prov,
JavaType origType)
throws JsonMappingException
{
// Very first thing, let's check if there is explicit serializer annotation:
final SerializationConfig config = prov.getConfig();
BeanDescription beanDesc = config.introspect(origType);
JsonSerializer<?> ser = findSerializerFromAnnotation(prov, beanDesc.getClassInfo());
if (ser != null) {
return (JsonSerializer<Object>) ser;
}
boolean staticTyping;
// Next: we may have annotations that further define types to use...
JavaType type = modifyTypeByAnnotation(config, beanDesc.getClassInfo(), origType);
if (type == origType) { // no changes, won't force static typing
staticTyping = false;
} else { // changes; assume static typing; plus, need to re-introspect if class differs
staticTyping = true;
if (!type.hasRawClass(origType.getRawClass())) {
beanDesc = config.introspect(type);
}
}
// Slight detour: do we have a Converter to consider?
Converter<Object,Object> conv = beanDesc.findSerializationConverter();
if (conv == null) { // no, simple
return (JsonSerializer<Object>) _createSerializer2(prov, type, beanDesc, staticTyping);
}
JavaType delegateType = conv.getOutputType(prov.getTypeFactory());
// One more twist,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> as per [Issue#288]; probably need to get new BeanDesc
if (!delegateType.hasRawClass(type.getRawClass())) {
beanDesc = config.introspect(delegateType);
// [#359]: explicitly check (again) for @JsonSerializer...
ser = findSerializerFromAnnotation(prov, beanDesc.getClassInfo());
}
// [databind#731]: Should skip if nominally java.lang.Object
if (ser == null && !delegateType.isJavaLangObject()) {
ser = _createSerializer2(prov, delegateType, beanDesc, true);
}
return new StdDelegatingSerializer(conv, delegateType, ser);
}
protected JsonSerializer<?> _createSerializer2(SerializerProvider prov,
JavaType type, BeanDescription beanDesc, boolean staticTyping)
throws JsonMappingException
{
JsonSerializer<?> ser = null;
final SerializationConfig config = prov.getConfig();
// Container types differ from non-container types
// (note: called method checks for module-provided serializers)
if (type.isContainerType()) {
if (!staticTyping) {
staticTyping = usesStaticTyping(config, beanDesc, null);
// [Issue#23]: Need to figure out how to force passed parameterization
// to stick...
/*
if (property == null) {
JavaType t = origType.getContentType();
if (t != null && !t.hasRawClass(Object.class)) {
staticTyping = true;
}
}
*/
}
// 03-Aug-2012, tatu: As per [Issue#40], may require POJO serializer...
ser = buildContainerSerializer(prov, type, beanDesc, staticTyping);
// Will return right away, since called method does post-processing:
if (ser != null) {
return ser;
}
} else {
// Modules may provide serializers of POJO types:
for (Serializers serializers : customSerializers()) {
ser = serializers.findSerializer(config, type, beanDesc);
if (ser != null) {
break;
}
}
// 25-Jun-2015, tatu: Then JsonSerializable, @JsonValue etc. NOTE! Prior to 2.6,
// this
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> call was BEFORE custom serializer lookup, which was wrong.
if (ser == null) {
ser = findSerializerByAnnotations(prov, type, beanDesc);
}
}
if (ser == null) {
// Otherwise, we will check "primary types"; both marker types that
// indicate specific handling (JsonSerializable), or main types that have
// precedence over container types
ser = findSerializerByLookup(type, config, beanDesc, staticTyping);
if (ser == null) {
ser = findSerializerByPrimaryType(prov, type, beanDesc, staticTyping);
if (ser == null) {
// And this is where this class comes in: if type is not a
// known "primary JDK type", perhaps it's a bean? We can still
// get a null, if we can't find a single suitable bean property.
ser = findBeanSerializer(prov, type, beanDesc);
// Finally: maybe we can still deal with it as an implementation of some basic JDK interface?
if (ser == null) {
ser = findSerializerByAddonType(config, type, beanDesc, staticTyping);
// 18-Sep-2014, tatu: Actually, as per [jackson-databind#539], need to get
// 'unknown' serializer assigned earlier, here, so that it gets properly
// post-processed
if (ser == null) {
ser = prov.getUnknownTypeSerializer(beanDesc.getBeanClass());
}
}
}
}
}
if (ser != null) {
// [databind#120]: Allow post-processing
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifySerializer(config, beanDesc, ser);
}
}
}
return ser;
}
/*
/**********************************************************
/* Other public methods that are not part of
/* JsonSerializerFactory API
/**********************************************************
*/
/**
* Method that will try to construct a {@link BeanSerializer} for
* given class. Returns null if no properties are found.
*/
public JsonSerializer<Object> findBeanSerializer(SerializerProvider prov, JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
// First things first: we know some types
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> are not beans...
if (!isPotentialBeanType(type.getRawClass())) {
// 03-Aug-2012, tatu: Except we do need to allow serializers for Enums,
// as per [Issue#24]
if (!type.isEnumType()) {
return null;
}
}
return constructBeanSerializer(prov, beanDesc);
}
/**
* Method called to create a type information serializer for values of given
* non-container property
* if one is needed. If not needed (no polymorphic handling configured), should
* return null.
*
* @param baseType Declared type to use as the base type for type information serializer
*
* @return Type serializer to use for property values, if one is needed; null if not.
*/
public TypeSerializer findPropertyTypeSerializer(JavaType baseType,
SerializationConfig config, AnnotatedMember accessor)
throws JsonMappingException
{
AnnotationIntrospector ai = config.getAnnotationIntrospector();
TypeResolverBuilder<?> b = ai.findPropertyTypeResolver(config, accessor, baseType);
TypeSerializer typeSer;
// Defaulting: if no annotations on member, check value class
if (b == null) {
typeSer = createTypeSerializer(config, baseType);
} else {
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(
config, accessor, baseType);
typeSer = b.buildTypeSerializer(config, baseType, subtypes);
}
return typeSer;
}
/**
* Method called to create a type information serializer for values of given
* container property
* if one is needed. If not needed (no polymorphic handling configured), should
* return null.
*
* @param containerType Declared type of the container to use as the base type for type information serializer
*
* @return Type serializer to use for property value contents, if one is needed; null if not.
*/
public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType,
SerializationConfig config, AnnotatedMember accessor)
throws JsonMappingException
{
JavaType contentType = containerType.getContentType();
AnnotationIntrospector ai = config.getAnnotationIntrospector();
TypeResolverBuilder<?> b = ai.findPropertyContentTypeResolver(config
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>, accessor, containerType);
TypeSerializer typeSer;
// Defaulting: if no annotations on member, check value class
if (b == null) {
typeSer = createTypeSerializer(config, contentType);
} else {
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config,
accessor, contentType);
typeSer = b.buildTypeSerializer(config, contentType, subtypes);
}
return typeSer;
}
/*
/**********************************************************
/* Overridable non-public factory methods
/**********************************************************
*/
/**
* Method called to construct serializer for serializing specified bean type.
*
* @since 2.1
*/
@SuppressWarnings("unchecked")
protected JsonSerializer<Object> constructBeanSerializer(SerializerProvider prov,
BeanDescription beanDesc)
throws JsonMappingException
{
// 13-Oct-2010, tatu: quick sanity check: never try to create bean serializer for plain Object
// 05-Jul-2012, tatu: ... but we should be able to just return "unknown type" serializer, right?
if (beanDesc.getBeanClass() == Object.class) {
return prov.getUnknownTypeSerializer(Object.class);
// throw new IllegalArgumentException("Can not create bean serializer for Object.class");
}
final SerializationConfig config = prov.getConfig();
BeanSerializerBuilder builder = constructBeanSerializerBuilder(beanDesc);
builder.setConfig(config);
// First: any detectable (auto-detect, annotations) properties to serialize?
List<BeanPropertyWriter> props = findBeanProperties(prov, beanDesc, builder);
if (props == null) {
props = new ArrayList<BeanPropertyWriter>();
} else {
props = removeOverlappingTypeIds(prov, beanDesc, builder, props);
}
// [databind#638]: Allow injection of "virtual" properties:
prov.getAnnotationIntrospector().findAndAddVirtualProperties(config, beanDesc.getClassInfo(), props);
// [JACKSON-440] Need to allow modification bean properties to serialize:
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
props = mod.changeProperties(config, bean
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Desc, props);
}
}
// Any properties to suppress?
props = filterBeanProperties(config, beanDesc, props);
// [JACKSON-440] Need to allow reordering of properties to serialize
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
props = mod.orderProperties(config, beanDesc, props);
}
}
/* And if Object Id is needed, some preparation for that as well: better
* do before view handling, mostly for the custom id case which needs
* access to a property
*/
builder.setObjectIdWriter(constructObjectIdHandler(prov, beanDesc, props));
builder.setProperties(props);
builder.setFilterId(findFilterId(config, beanDesc));
AnnotatedMember anyGetter = beanDesc.findAnyGetter();
if (anyGetter != null) {
if (config.canOverrideAccessModifiers()) {
anyGetter.fixAccess();
}
JavaType type = anyGetter.getType(beanDesc.bindingsForBeanType());
// copied from BasicSerializerFactory.buildMapSerializer():
boolean staticTyping = config.isEnabled(MapperFeature.USE_STATIC_TYPING);
JavaType valueType = type.getContentType();
TypeSerializer typeSer = createTypeSerializer(config, valueType);
// last 2 nulls; don't know key, value serializers (yet)
// 23-Feb-2015, tatu: As per [#705], need to support custom serializers
JsonSerializer<?> anySer = findSerializerFromAnnotation(prov, anyGetter);
if (anySer == null) {
// TODO: support '@JsonIgnoreProperties' with any setter?
anySer = MapSerializer.construct(/* ignored props*/ null, type, staticTyping,
typeSer, null, null, /*filterId*/ null);
}
// TODO: can we find full PropertyName?
PropertyName name = PropertyName.construct(anyGetter.getName());
BeanProperty.Std anyProp = new BeanProperty.Std(name, valueType, null,
beanDesc.getClassAnnotations(), anyGetter, PropertyMetadata.STD_OPTIONAL);
builder.setAnyGetter(new AnyGetterWriter(anyProp, anyGetter, anySer));
}
// Next: need to gather view
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> information, if any:
processViews(config, builder);
// Finally: let interested parties mess with the result bit more...
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
builder = mod.updateBuilder(config, beanDesc, builder);
}
}
JsonSerializer<Object> ser = (JsonSerializer<Object>) builder.build();
if (ser == null) {
// If we get this far, there were no properties found, so no regular BeanSerializer
// would be constructed. But, couple of exceptions.
// First: if there are known annotations, just create 'empty bean' serializer
if (beanDesc.hasKnownClassAnnotations()) {
return builder.createDummy();
}
}
return ser;
}
protected ObjectIdWriter constructObjectIdHandler(SerializerProvider prov,
BeanDescription beanDesc, List<BeanPropertyWriter> props)
throws JsonMappingException
{
ObjectIdInfo objectIdInfo = beanDesc.getObjectIdInfo();
if (objectIdInfo == null) {
return null;
}
ObjectIdGenerator<?> gen;
Class<?> implClass = objectIdInfo.getGeneratorType();
// Just one special case: Property-based generator is trickier
if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
String propName = objectIdInfo.getPropertyName().getSimpleName();
BeanPropertyWriter idProp = null;
for (int i = 0, len = props.size() ;; ++i) {
if (i == len) {
throw new IllegalArgumentException("Invalid Object Id definition for "+beanDesc.getBeanClass().getName()
+": can not find property with name '"+propName+"'");
}
BeanPropertyWriter prop = props.get(i);
if (propName.equals(prop.getName())) {
idProp = prop;
/* Let's force it to be the first property to output
* (although it may still get rearranged etc)
*/
if (i > 0) {
props.remove(i);
props.add(0, idProp);
}
break;
}
}
JavaType idType = idProp.getType();
gen = new PropertyBasedObjectIdGenerator(objectIdInfo, idProp);
// one more thing: must
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> ensure that ObjectIdWriter does not actually write the value:
return ObjectIdWriter.construct(idType, (PropertyName) null, gen, objectIdInfo.getAlwaysAsId());
}
// other types are simpler
JavaType type = prov.constructType(implClass);
// Could require type to be passed explicitly, but we should be able to find it too:
JavaType idType = prov.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
gen = prov.objectIdGeneratorInstance(beanDesc.getClassInfo(), objectIdInfo);
return ObjectIdWriter.construct(idType, objectIdInfo.getPropertyName(), gen,
objectIdInfo.getAlwaysAsId());
}
/**
* Method called to construct a filtered writer, for given view
* definitions. Default implementation constructs filter that checks
* active view type to views property is to be included in.
*/
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer,
Class<?>[] inViews)
{
return FilteredBeanPropertyWriter.constructViewBased(writer, inViews);
}
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config,
BeanDescription beanDesc)
{
return new PropertyBuilder(config, beanDesc);
}
protected BeanSerializerBuilder constructBeanSerializerBuilder(BeanDescription beanDesc) {
return new BeanSerializerBuilder(beanDesc);
}
/*
/**********************************************************
/* Overridable non-public introspection methods
/**********************************************************
*/
/**
* Helper method used to skip processing for types that we know
* can not be (i.e. are never consider to be) beans:
* things like primitives, Arrays, Enums, and proxy types.
*<p>
* Note that usually we shouldn't really be getting these sort of
* types anyway; but better safe than sorry.
*/
protected boolean isPotentialBeanType(Class<?> type)
{
return (ClassUtil.canBeABeanType(type) == null) && !ClassUtil.isProxyType(type);
}
/**
* Method used to collect all actual serializable properties.
* Can be overridden to implement custom detection schemes.
*/
protected List<BeanPropertyWriter> findBeanProperties(SerializerProvider prov,
BeanDescription beanDesc, BeanSerializerBuilder builder)
throws JsonMappingException
{
List<
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>BeanPropertyDefinition> properties = beanDesc.findProperties();
final SerializationConfig config = prov.getConfig();
// [JACKSON-429]: ignore specified types
removeIgnorableTypes(config, beanDesc, properties);
// and possibly remove ones without matching mutator...
if (config.isEnabled(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS)) {
removeSetterlessGetters(config, beanDesc, properties);
}
// nothing? can't proceed (caller may or may not throw an exception)
if (properties.isEmpty()) {
return null;
}
// null is for value type serializer, which we don't have access to from here (ditto for bean prop)
boolean staticTyping = usesStaticTyping(config, beanDesc, null);
PropertyBuilder pb = constructPropertyBuilder(config, beanDesc);
ArrayList<BeanPropertyWriter> result = new ArrayList<BeanPropertyWriter>(properties.size());
TypeBindings typeBind = beanDesc.bindingsForBeanType();
for (BeanPropertyDefinition property : properties) {
final AnnotatedMember accessor = property.getAccessor();
// [JACKSON-762]: type id? Requires special handling:
if (property.isTypeId()) {
if (accessor != null) { // only add if we can access... but otherwise?
if (config.canOverrideAccessModifiers()) {
accessor.fixAccess();
}
builder.setTypeId(accessor);
}
continue;
}
// [JACKSON-235]: suppress writing of back references
AnnotationIntrospector.ReferenceProperty refType = property.findReferenceType();
if (refType != null && refType.isBackReference()) {
continue;
}
if (accessor instanceof AnnotatedMethod) {
result.add(_constructWriter(prov, property, typeBind, pb, staticTyping, (AnnotatedMethod) accessor));
} else {
result.add(_constructWriter(prov, property, typeBind, pb, staticTyping, (AnnotatedField) accessor));
}
}
return result;
}
/*
/**********************************************************
/* Overridable non-public methods for manipulating bean properties
/**********************************************************
*/
/**
* Overridable method that can filter out properties. Default implementation
* checks annotations class may have.
*/
protected List<Bean
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
* @since 2.6
*/
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializerProvider prov,
BeanDescription beanDesc, BeanSerializerBuilder builder,
List<BeanPropertyWriter> props)
{
for (int i = 0, end = props.size(); i < end; ++i) {
BeanPropertyWriter bpw = props.get(i);
TypeSerializer td = bpw.getTypeSerializer();
if ((td == null) || (td.getTypeInclusion() != As.EXTERNAL_PROPERTY)) {
continue;
}
String n = td.getPropertyName();
PropertyName typePropName = PropertyName.construct(n);
for (BeanPropertyWriter w2 : props) {
if ((w2 != bpw) && w2.wouldConflictWithName(typePropName)) {
bpw.assignTypeSerializer(null);
break;
}
}
}
return props;
}
/*
/**********************************************************
/* Internal helper methods
/**********************************************************
*/
/**
* Secondary helper method for constructing {@link BeanPropertyWriter} for
* given member (field or method).
*/
protected BeanPropertyWriter _constructWriter(SerializerProvider prov,
BeanPropertyDefinition propDef, TypeBindings typeContext,
PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor)
throws JsonMappingException
{
final PropertyName name = propDef.getFullName();
if (prov.canOverrideAccessModifiers()) {
accessor.fixAccess();
}
JavaType type = accessor.getType(typeContext);
BeanProperty.Std property = new BeanProperty.Std(name, type, propDef.getWrapperName(),
pb.getClassAnnotations(), accessor, propDef.getMetadata());
// Does member specify a serializer? If so, let's use it.
JsonSerializer<?> annotatedSerializer = findSerializerFromAnnotation(prov,
accessor);
/* 02-Feb-2012, tatu: Unlike most other code paths, serializer produced
* here will NOT be resolved or contextualized, unless done here, so:
*/
if (annotatedSerializer instanceof ResolvableSerializer) {
((ResolvableSerializer) annotatedSerializer).resolve(prov);
}
// 05-Sep-2013, tatu: should be primary property serializer so:
annotatedSerializer = prov
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>.handlePrimaryContextualization(annotatedSerializer, property);
// And how about polymorphic typing? First special to cover JAXB per-field settings:
TypeSerializer contentTypeSer = null;
// 16-Feb-2014, cgc: contentType serializers for collection-like and map-like types
if (ClassUtil.isCollectionMapOrArray(type.getRawClass())
|| type.isCollectionLikeType() || type.isMapLikeType()) {
contentTypeSer = findPropertyContentTypeSerializer(type, prov.getConfig(), accessor);
}
// and if not JAXB collection/array with annotations, maybe regular type info?
TypeSerializer typeSer = findPropertyTypeSerializer(type, prov.getConfig(), accessor);
BeanPropertyWriter pbw = pb.buildWriter(prov, propDef, type, annotatedSerializer,
typeSer, contentTypeSer, accessor, staticTyping);
return pbw;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> = _constructConstructor(ctor, true);
} else {
if (constructors == null) {
constructors = new ArrayList<AnnotatedConstructor>(Math.max(10, declaredCtors.length));
}
constructors.add(_constructConstructor(ctor, false));
}
}
if (constructors == null) {
_constructors = Collections.emptyList();
} else {
_constructors = constructors;
}
// and if need be, augment with mix-ins
if (_primaryMixIn != null) {
if (_defaultConstructor != null || !_constructors.isEmpty()) {
_addConstructorMixIns(_primaryMixIn);
}
}
/* And then... let's remove all constructors that are deemed
* ignorable after all annotations have been properly collapsed.
*/
// 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
if (_annotationIntrospector != null) {
if (_defaultConstructor != null) {
if (_annotationIntrospector.hasIgnoreMarker(_defaultConstructor)) {
_defaultConstructor = null;
}
}
if (_constructors != null) {
// count down to allow safe removal
for (int i = _constructors.size(); --i >= 0; ) {
if (_annotationIntrospector.hasIgnoreMarker(_constructors.get(i))) {
_constructors.remove(i);
}
}
}
}
List<AnnotatedMethod> creatorMethods = null;
// Then static methods which are potential factory methods
for (Method m : _findClassMethods(_class)) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
// all factory methods are fine, as per [JACKSON-850]
//int argCount = m.getParameterTypes().length;
if (creatorMethods == null) {
creatorMethods = new ArrayList<AnnotatedMethod>(8);
}
creatorMethods.add(_constructCreatorMethod(m));
}
if (creatorMethods == null) {
_creatorMethods = Collections.emptyList();
} else {
_creatorMethods = creatorMethods;
// mix-ins to mix in?
if (_primaryMixIn != null) {
_addFactoryMixIns(_primaryMixIn
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>);
}
// anything to ignore at this point?
if (_annotationIntrospector != null) {
// count down to allow safe removal
for (int i = _creatorMethods.size(); --i >= 0; ) {
if (_annotationIntrospector.hasIgnoreMarker(_creatorMethods.get(i))) {
_creatorMethods.remove(i);
}
}
}
}
_creatorsResolved = true;
}
/**
* Method for resolving member method information: aggregating all non-static methods
* and combining annotations (to implement method-annotation inheritance)
*
* @param methodFilter Filter used to determine which methods to include
*/
private void resolveMemberMethods()
{
_memberMethods = new AnnotatedMethodMap();
AnnotatedMethodMap mixins = new AnnotatedMethodMap();
// first: methods from the class itself
_addMemberMethods(_class, _memberMethods, _primaryMixIn, mixins);
// and then augment these with annotations from super-types:
for (Class<?> cls : _superTypes) {
Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(cls);
_addMemberMethods(cls, _memberMethods, mixin, mixins);
}
// Special case: mix-ins for Object.class? (to apply to ALL classes)
if (_mixInResolver != null) {
Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class);
if (mixin != null) {
_addMethodMixIns(_class, _memberMethods, mixin, mixins);
}
}
/* Any unmatched mix-ins? Most likely error cases (not matching
* any method); but there is one possible real use case:
* exposing Object#hashCode (alas, Object#getClass can NOT be
* exposed, see [JACKSON-140])
*/
// 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
if (_annotationIntrospector != null) {
if (!mixins.isEmpty()) {
Iterator<AnnotatedMethod> it = mixins.iterator();
while (it.hasNext()) {
AnnotatedMethod mixIn = it.next();
try {
Method
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>(annotations, parent.getDeclaredAnnotations());
}
}
/*
/**********************************************************
/* Helper methods for populating creator (ctor, factory) information
/**********************************************************
*/
protected void _addConstructorMixIns(Class<?> mixin)
{
MemberKey[] ctorKeys = null;
int ctorCount = (_constructors == null) ? 0 : _constructors.size();
for (Constructor<?> ctor : mixin.getDeclaredConstructors()) {
if (ctor.getParameterTypes().length == 0) {
if (_defaultConstructor != null) {
_addMixOvers(ctor, _defaultConstructor, false);
}
} else {
if (ctorKeys == null) {
ctorKeys = new MemberKey[ctorCount];
for (int i = 0; i < ctorCount; ++i) {
ctorKeys[i] = new MemberKey(_constructors.get(i).getAnnotated());
}
}
MemberKey key = new MemberKey(ctor);
for (int i = 0; i < ctorCount; ++i) {
if (!key.equals(ctorKeys[i])) {
continue;
}
_addMixOvers(ctor, _constructors.get(i), true);
break;
}
}
}
}
protected void _addFactoryMixIns(Class<?> mixin)
{
MemberKey[] methodKeys = null;
int methodCount = _creatorMethods.size();
for (Method m : mixin.getDeclaredMethods()) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
if (m.getParameterTypes().length == 0) {
continue;
}
if (methodKeys == null) {
methodKeys = new MemberKey[methodCount];
for (int i = 0; i < methodCount; ++i) {
methodKeys[i] = new MemberKey(_creatorMethods.get(i).getAnnotated());
}
}
MemberKey key = new MemberKey(m);
for (int i = 0; i < methodCount; ++i) {
if (!key.equals(methodKeys[i])) {
continue;
}
_addMixOvers(m, _creatorMethods.get(i), true);
break;
}
}
}
/*
/********************************************************
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Suppressed(e); Not until 1.7
throw ex;
}
return contextClass.getDeclaredMethods(); // Cross fingers
}
}
/*
/**********************************************************
/* Other methods
/**********************************************************
*/
@Override
public String toString() {
return "[AnnotedClass "+_class.getName()+"]";
}
@Override
public int hashCode() {
return _class.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedClass) o)._class == _class;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>(PropertyName newName) {
return new POJOPropertyBuilder(this, newName);
}
@Override
public POJOPropertyBuilder withSimpleName(String newSimpleName)
{
PropertyName newName = _name.withSimpleName(newSimpleName);
return (newName == _name) ? this : new POJOPropertyBuilder(this, newName);
}
/*
/**********************************************************
/* Comparable implementation: sort alphabetically, except
/* that properties with constructor parameters sorted
/* before other properties
/**********************************************************
*/
@Override
public int compareTo(POJOPropertyBuilder other)
{
// first, if one has ctor params, that should come first:
if (_ctorParameters != null) {
if (other._ctorParameters == null) {
return -1;
}
} else if (other._ctorParameters != null) {
return 1;
}
/* otherwise sort by external name (including sorting of
* ctor parameters)
*/
return getName().compareTo(other.getName());
}
/*
/**********************************************************
/* BeanPropertyDefinition implementation, name/type
/**********************************************************
*/
@Override
public String getName() {
return (_name == null) ? null : _name.getSimpleName();
}
@Override
public PropertyName getFullName() {
return _name;
}
@Override
public boolean hasName(PropertyName name) {
return _name.equals(name);
}
@Override
public String getInternalName() { return _internalName.getSimpleName(); }
@Override
public PropertyName getWrapperName() {
/* 13-Mar-2013, tatu: Accessing via primary member SHOULD work,
* due to annotation merging. However, I have seen some problems
* with this access (for other annotations)... so if this should
* occur, try commenting out full traversal code
*/
AnnotatedMember member = getPrimaryMember();
return (member == null || _annotationIntrospector == null) ? null
: _annotationIntrospector.findWrapperName(member);
/*
return fromMemberAnnotations(new WithMember<PropertyName>() {
@Override
public PropertyName withMember(AnnotatedMember member) {
return _annotationIntrospector.findWrapperName(member);
}
});
*/
}
@
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> null) && (result != defaultValue)) {
return result;
}
}
if (_setters != null) {
T result = func.withMember(_setters.value);
if ((result != null) && (result != defaultValue)) {
return result;
}
}
if (_fields != null) {
T result = func.withMember(_fields.value);
if ((result != null) && (result != defaultValue)) {
return result;
}
}
if (_getters != null) {
T result = func.withMember(_getters.value);
if ((result != null) && (result != defaultValue)) {
return result;
}
}
return null;
}
/*
/**********************************************************
/* Helper classes
/**********************************************************
*/
private interface WithMember<T> {
public T withMember(AnnotatedMember member);
}
/**
* @since 2.5
*/
protected static class MemberIterator<T extends AnnotatedMember>
implements Iterator<T>
{
private Linked<T> next;
public MemberIterator(Linked<T> first) {
next = first;
}
@Override
public boolean hasNext() {
return (next != null);
}
@Override
public T next() {
if (next == null) throw new NoSuchElementException();
T result = next.value;
next = next.next;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
/**
* Node used for creating simple linked lists to efficiently store small sets
* of things.
*/
private final static class Linked<T>
{
public final T value;
public final Linked<T> next;
public final PropertyName name;
public final boolean isNameExplicit;
public final boolean isVisible;
public final boolean isMarkedIgnored;
public Linked(T v, Linked<T> n,
PropertyName name, boolean explName, boolean visible, boolean ignored)
{
value = v;
next = n;
// ensure that we'll never have missing names
this.name = (name == null || name.isEmpty()) ? null : name;
if (explName) {
if (this.name == null) { // sanity check to catch internal problems
throw new IllegalArgumentException
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.DateFormat;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
/**
* Compared to regular {@link java.util.Date} serialization, we do use String
* representation here. Why? Basically to truncate of time part, since
* that should not be used by plain SQL date.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class SqlDateSerializer
extends DateTimeSerializerBase<java.sql.Date>
{
public SqlDateSerializer() {
/* 12-Apr-2014, tatu: for now, pass explicit 'false' to mean 'not using timestamp',
* for backwards compatibility; this differs from other Date/Calendar types.
*/
this(Boolean.FALSE);
}
protected SqlDateSerializer(Boolean useTimestamp) {
super(java.sql.Date.class, useTimestamp, null);
}
@Override
public SqlDateSerializer withFormat(Boolean timestamp, DateFormat customFormat) {
return new SqlDateSerializer(timestamp);
}
@Override
protected long _timestamp(java.sql.Date value) {
return (value == null) ? 0L : value.getTime();
}
@Override
public void serialize(java.sql.Date value, JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
if (_asTimestamp(provider)) {
gen.writeNumber(_timestamp(value));
} else {
gen.writeString(value.toString());
}
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
//todo: (ryan) add a format for the date in the schema?
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
_acceptJsonFormatVisitor
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>VirtualBeanPropertyWriter base, PropertyName name) {
super(base, name);
}
protected static boolean _suppressNulls(JsonInclude.Include inclusion) {
return (inclusion != JsonInclude.Include.ALWAYS);
}
protected static Object _suppressableValue(JsonInclude.Include inclusion) {
if ((inclusion == JsonInclude.Include.NON_EMPTY)
|| (inclusion == JsonInclude.Include.NON_EMPTY)) {
return MARKER_FOR_EMPTY;
}
return null;
}
/*
/**********************************************************
/* Standard accessor overrides
/**********************************************************
*/
@Override
public boolean isVirtual() { return true; }
@Override
public Class<?> getPropertyType() {
return _declaredType.getRawClass();
}
@Override
public Type getGenericPropertyType() {
return getPropertyType();
}
/*
/**********************************************************
/* Abstract methods for sub-classes to define
/**********************************************************
*/
/**
* Method called to figure out the value to serialize. For simple sub-types
* (such as {@link com.fasterxml.jackson.databind.ser.impl.AttributePropertyWriter})
* this may be one of few methods to define, although more advanced implementations
* may choose to not even use this method (by overriding {@link #serializeAsField})
* and define a bogus implementation.
*/
protected abstract Object value(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception;
/**
* Contextualization method called on a newly constructed virtual bean property.
* Usually a new intance needs to be created due to finality of some of configuration
* members; otherwise while recommended, creating a new instance is not strictly-speaking
* mandatory because calls are made in thread-safe manner, as part of initialization
* before use.
*
* @param config Currenct configuration; guaranteed to be {@link SerializationConfig}
* (just not typed since caller does not have dependency to serialization-specific types)
* @param declaringClass Class that contains this property writer
* @param propDef Nominal property definition to use
* @param type Declared type for the property
*/
public abstract VirtualBeanPropertyWriter withConfig(MapperConfig<?> config,
AnnotatedClass declaringClass, BeanPropertyDefinition propDef, JavaType type);
/*
/**********************************************************
/*
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> PropertyWriter serialization method overrides
/**********************************************************
*/
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
// NOTE: mostly copied from base class, but off-lined get() access
final Object value = value(bean, gen, prov);
if (value == null) {
if (_nullSerializer != null) {
gen.writeFieldName(_name);
_nullSerializer.serialize(null, gen, prov);
}
return;
}
JsonSerializer<Object> ser = _serializer;
if (ser == null) {
Class<?> cls = value.getClass();
PropertySerializerMap m = _dynamicSerializers;
ser = m.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(m, cls, prov);
}
}
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
return;
}
} else if (_suppressableValue.equals(value)) {
return;
}
}
if (value == bean) { // simple check for direct cycles
// three choices: exception; handled by call; or pass-through
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
gen.writeFieldName(_name);
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
// This one's fine as-is from base class
//public void serializeAsOmittedField(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception
@Override
public void serializeAsElement(Object bean, JsonGenerator gen, SerializerProvider prov)
throws Exception
{
// NOTE: mostly copied from base class, but off-lined get() access
final Object value = value(bean, gen, prov);
if (value == null) {
if (_nullSerializer != null) {
_nullSerializer.serialize(null, gen, prov);
} else {
gen.writeNull();
}
return;
}
JsonSerializer<Object> ser = _serializer;
if (ser == null)
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> {
Class<?> cls = value.getClass();
PropertySerializerMap map = _dynamicSerializers;
ser = map.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(map, cls, prov);
}
}
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(prov, value)) {
serializeAsPlaceholder(bean, gen, prov);
return;
}
} else if (_suppressableValue.equals(value)) {
serializeAsPlaceholder(bean, gen, prov);
return;
}
}
if (value == bean) {
if (_handleSelfReference(bean, gen, prov, ser)) {
return;
}
}
if (_typeSerializer == null) {
ser.serialize(value, gen, prov);
} else {
ser.serializeWithType(value, gen, prov, _typeSerializer);
}
}
// This one's fine as-is from base class
//public void serializeAsPlaceholder(Object bean, JsonGenerator jgen, SerializerProvider prov)
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> _type = type;
_class = null;
_isTyped = true;
_hashCode = typedHash(type);
}
public final void resetUntyped(JavaType type) {
_type = type;
_class = null;
_isTyped = false;
_hashCode = untypedHash(type);
}
public boolean isTyped() {
return _isTyped;
}
public Class<?> getRawType() {
return _class;
}
public JavaType getType() {
return _type;
}
@Override public final int hashCode() { return _hashCode; }
@Override public final String toString() {
if (_class != null) {
return "{class: "+_class.getName()+", typed? "+_isTyped+"}";
}
return "{type: "+_type+", typed? "+_isTyped+"}";
}
// note: we assume key is never used for anything other than as map key, so:
@Override public final boolean equals(Object o)
{
if (o == null) return false;
if (o == this) return true;
if (o.getClass() != getClass()) {
return false;
}
TypeKey other = (TypeKey) o;
if (other._isTyped == _isTyped) {
if (_class != null) {
return other._class == _class;
}
return _type.equals(other._type);
}
return false;
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
FromStringDeserializer<?> deser = FromStringDeserializer.findDeserializer(Currency.class);
return new StdKeyDeserializer(TYPE_CURRENCY, raw, deser);
} else {
return null;
}
return new StdKeyDeserializer(kind, raw);
}
@Override
public Object deserializeKey(String key, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
if (key == null) { // is this even legal call?
return null;
}
try {
Object result = _parse(key, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
throw ctxt.weirdKeyException(_keyClass, key, "not a valid representation: "+re.getMessage());
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
throw ctxt.weirdKeyException(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
return Boolean.TRUE;
}
if ("false".equals(key)) {
return Boolean.FALSE;
}
throw ctxt.weirdKeyException(_keyClass, key, "value not 'true' or 'false'");
case TYPE_BYTE:
{
int value = _parseInt(key);
// as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
throw ctxt.weirdKeyException(_keyClass, key, "overflow, value can not be represented as 8-bit value");
}
return Byte.valueOf((byte) value);
}
case TYPE_SHORT:
{
int value = _parseInt(key);
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdKeyException(_keyClass, key, "overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>short) value);
}
case TYPE_CHAR:
if (key.length() == 1) {
return Character.valueOf(key.charAt(0));
}
throw ctxt.weirdKeyException(_keyClass, key, "can only convert 1-character Strings");
case TYPE_INT:
return _parseInt(key);
case TYPE_LONG:
return _parseLong(key);
case TYPE_FLOAT:
// Bounds/range checks would be tricky here, so let's not bother even trying...
return Float.valueOf((float) _parseDouble(key));
case TYPE_DOUBLE:
return _parseDouble(key);
case TYPE_LOCALE:
try {
return _deser._deserialize(key, ctxt);
} catch (IOException e) {
throw ctxt.weirdKeyException(_keyClass, key, "unable to parse key as locale");
}
case TYPE_CURRENCY:
try {
return _deser._deserialize(key, ctxt);
} catch (IOException e) {
throw ctxt.weirdKeyException(_keyClass, key, "unable to parse key as currency");
}
case TYPE_DATE:
return ctxt.parseDate(key);
case TYPE_CALENDAR:
java.util.Date date = ctxt.parseDate(key);
return (date == null) ? null : ctxt.constructCalendar(date);
case TYPE_UUID:
return UUID.fromString(key);
case TYPE_URI:
return URI.create(key);
case TYPE_URL:
return new URL(key);
case TYPE_CLASS:
try {
return ctxt.findClass(key);
} catch (Exception e) {
throw ctxt.weirdKeyException(_keyClass, key, "unable to parse key as Class");
}
}
return null;
}
/*
/**********************************************************
/* Helper methods for sub-classes
/**********************************************************
*/
protected int _parseInt(String key) throws IllegalArgumentException {
return Integer.parseInt(key);
}
protected long _parseLong(String key) throws IllegalArgumentException {
return Long.parseLong(key);
}
protected double _parseDouble(String key) throws IllegalArgumentException {
return NumberInput.parseDouble(key);
}
/*
/**********************************************************
/* First: the standard "String as String
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>-2012, tatu: One more thing -- if explicit content type is annotated,
// we can consider it a static case as well.
// 20-Aug-2013, tatu: Need to avoid trying to access serializer for java.lang.Object tho
if ((_valueTypeIsStatic && _valueType.getRawClass() != Object.class)
|| hasContentTypeAnnotation(provider, property)) {
ser = provider.findValueSerializer(_valueType, property);
}
} else {
ser = provider.handleSecondaryContextualization(ser, property);
}
if (keySer == null) {
keySer = _keySerializer;
}
if (keySer == null) {
keySer = provider.findKeySerializer(_keyType, property);
} else {
keySer = provider.handleSecondaryContextualization(keySer, property);
}
MapEntrySerializer mser = withResolved(property, keySer, ser);
// but note: no filtering, ignored entries or sorting (unlike Maps)
return mser;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _valueType;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _valueSerializer;
}
@Override
public boolean hasSingleElement(Map.Entry<?,?> value) {
return true;
}
@Override
public boolean isEmpty(SerializerProvider prov, Entry<?, ?> value) {
return (value == null);
}
/*
/**********************************************************
/* Serialization methods
/**********************************************************
*/
@Override
public void serialize(Map.Entry<?, ?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
gen.writeStartObject();
// [databind#631]: Assign current value, to be accessible by custom serializers
gen.setCurrentValue(value);
if (_valueSerializer != null) {
serializeUsing(value, gen, provider, _valueSerializer);
} else {
serializeDynamic(value, gen, provider);
}
gen.writeEndObject();
}
@Override
public void serializeWithType(Map.Entry<?, ?> value, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
typeSer.writeTypePrefixForObject
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>.class</code> would; that is, that
* nothing is known about handled type.
*<p>
*/
public Class<T> handledType() { return null; }
/**
* Method called to check whether given serializable value is
* considered "empty" value (for purposes of suppressing serialization
* of empty values).
*<p>
* Default implementation will consider only null values to be empty.
*
* @since 2.0
*
* @deprecated Since 2.5 Use {@link #isEmpty(SerializerProvider, Object)} instead;
* will be removed from 2.7
*/
@Deprecated
public boolean isEmpty(T value) {
return isEmpty(null, value);
}
/**
* Method called to check whether given serializable value is
* considered "empty" value (for purposes of suppressing serialization
* of empty values).
*<p>
* Default implementation will consider only null values to be empty.
*<p>
* NOTE: replaces {@link #isEmpty(Object)}, deprecated in 2.5
*
* @since 2.5
*/
public boolean isEmpty(SerializerProvider provider, T value) {
return (value == null);
}
/**
* Method that can be called to see whether this serializer instance
* will use Object Id to handle cyclic references.
*/
public boolean usesObjectId() {
return false;
}
/**
* Accessor for checking whether this serializer is an
* "unwrapping" serializer; this is necessary to know since
* it may also require caller to suppress writing of the
* leading property name.
*/
public boolean isUnwrappingSerializer() {
return false;
}
/**
* Accessor that can be used to determine if this serializer uses
* another serializer for actual serialization, by delegating
* calls. If so, will return immediate delegate (which itself may
* delegate to further serializers); otherwise will return null.
*
* @return Serializer this serializer delegates calls to, if null;
* null otherwise.
*
* @since 2.1
*/
public JsonSerializer<?> getDelegatee() {
return null;
}
/**
* Accessor for iterating over logical properties that the type
* handled by this serializer has, from serialization perspective.
* Actual
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.impl;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
import com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase;
/**
* This is an optimized serializer for Lists that can be efficiently
* traversed by index (as opposed to others, such as {@link LinkedList}
* that can not}.
*/
@JacksonStdImpl
public final class IndexedListSerializer
extends AsArraySerializerBase<List<?>>
{
private static final long serialVersionUID = 1L;
public IndexedListSerializer(JavaType elemType, boolean staticTyping, TypeSerializer vts,
JsonSerializer<Object> valueSerializer)
{
super(List.class, elemType, staticTyping, vts, valueSerializer);
}
public IndexedListSerializer(IndexedListSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public IndexedListSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new IndexedListSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, List<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(List<?> value) {
return (value.size() == 1);
}
@Override
public ContainerSerializer<?> _withValueTypeSerializer(TypeSerializer vts) {
return new IndexedListSerializer(this,
_property, vts, _elementSerializer, _unwrapSingle);
}
@Override
public final void serialize(List<?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.size();
if (len ==
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Detect.Visibility visibility) {
return _withBase( _base.withVisibility(forMethod, visibility));
}
@Override
public DeserializationConfig with(TypeResolverBuilder<?> trb) {
return _withBase(_base.withTypeResolverBuilder(trb));
}
@Override
public DeserializationConfig with(SubtypeResolver str) {
return (_subtypeResolver == str) ? this : new DeserializationConfig(this, str);
}
@Override
public DeserializationConfig with(PropertyNamingStrategy pns) {
return _withBase(_base.withPropertyNamingStrategy(pns));
}
@Override
public DeserializationConfig withRootName(PropertyName rootName) {
if (rootName == null) {
if (_rootName == null) {
return this;
}
} else if (rootName.equals(_rootName)) {
return this;
}
return new DeserializationConfig(this, rootName);
}
@Override
public DeserializationConfig with(TypeFactory tf) {
return _withBase( _base.withTypeFactory(tf));
}
@Override
public DeserializationConfig with(DateFormat df) {
return _withBase(_base.withDateFormat(df));
}
@Override
public DeserializationConfig with(HandlerInstantiator hi) {
return _withBase(_base.withHandlerInstantiator(hi));
}
@Override
public DeserializationConfig withInsertedAnnotationIntrospector(AnnotationIntrospector ai) {
return _withBase(_base.withInsertedAnnotationIntrospector(ai));
}
@Override
public DeserializationConfig withAppendedAnnotationIntrospector(AnnotationIntrospector ai) {
return _withBase(_base.withAppendedAnnotationIntrospector(ai));
}
@Override
public DeserializationConfig withView(Class<?> view) {
return (_view == view) ? this : new DeserializationConfig(this, view);
}
@Override
public DeserializationConfig with(Locale l) {
return _withBase(_base.with(l));
}
@Override
public DeserializationConfig with(TimeZone tz) {
return _withBase(_base.with(tz));
}
@Override
public DeserializationConfig with(Base64Variant base64) {
return _withBase(_base.with(base
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> (try to)
* resolve non-fatal deserialization problems.
*/
public DeserializationConfig withHandler(DeserializationProblemHandler h)
{
// Sanity check: let's prevent adding same handler multiple times
if (LinkedNode.contains(_problemHandlers, h)) {
return this;
}
return new DeserializationConfig(this,
new LinkedNode<DeserializationProblemHandler>(h, _problemHandlers));
}
/**
* Method for removing all configured problem handlers; usually done to replace
* existing handler(s) with different one(s)
*/
public DeserializationConfig withNoProblemHandlers() {
if (_problemHandlers == null) {
return this;
}
return new DeserializationConfig(this,
(LinkedNode<DeserializationProblemHandler>) null);
}
/*
/**********************************************************
/* JsonParser initialization
/**********************************************************
*/
/**
* Method called by {@link ObjectMapper} and {@link ObjectReader}
* to modify those {@link com.fasterxml.jackson.core.JsonParser.Feature} settings
* that have been configured via this config instance.
*
* @since 2.5
*/
public void initialize(JsonParser p) {
if (_parserFeaturesToChange != 0) {
int orig = p.getFeatureMask();
int newFlags = (orig & ~_parserFeaturesToChange) | _parserFeatures;
if (orig != newFlags) {
p.setFeatureMask(newFlags);
}
}
}
/*
/**********************************************************
/* MapperConfig implementation
/**********************************************************
*/
/**
* Method for getting {@link AnnotationIntrospector} configured
* to introspect annotation values used for configuration.
*/
@Override
public AnnotationIntrospector getAnnotationIntrospector()
{
/* 29-Jul-2009, tatu: it's now possible to disable use of
* annotations; can be done using "no-op" introspector
*/
if (isEnabled(MapperFeature.USE_ANNOTATIONS)) {
return super.getAnnotationIntrospector();
}
return NopAnnotationIntrospector.instance;
}
@Override
public boolean useRootWrapping()
{
if (_rootName != null) { // empty String disables wrapping; non-empty enables
return !_rootName.isEmpty();
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> + _index;
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
AnnotatedParameter other = (AnnotatedParameter) o;
return other._owner.equals(_owner) && (other._index == _index);
}
@Override
public String toString() {
return "[parameter #"+getIndex()+", annotations: "+_annotations+"]";
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 64-bit integer values.
*/
public class BigIntegerNode
extends NumericNode
{
private final static BigInteger MIN_INTEGER = BigInteger.valueOf(Integer.MIN_VALUE);
private final static BigInteger MAX_INTEGER = BigInteger.valueOf(Integer.MAX_VALUE);
private final static BigInteger MIN_LONG = BigInteger.valueOf(Long.MIN_VALUE);
private final static BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);
final protected BigInteger _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public BigIntegerNode(BigInteger v) { _value = v; }
public static BigIntegerNode valueOf(BigInteger v) { return new BigIntegerNode(v); }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.BIG_INTEGER; }
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isBigInteger() { return true; }
@Override public boolean canConvertToInt() {
return (_value.compareTo(MIN_INTEGER) >= 0) && (_value.compareTo(MAX_INTEGER) <= 0);
}
@Override public boolean canConvertToLong() {
return (_value.compareTo(MIN_LONG) >= 0) && (_value.compareTo(MAX_LONG) <= 0);
}
@Override
public Number numberValue() {
return _value;
}
@Override
public short shortValue() { return _value.shortValue(); }
@Override
public int intValue() { return _value.intValue(); }
@Override
public long longValue() { return _value.longValue(); }
@Override
public BigInteger bigIntegerValue() { return _value; }
@Override
public float floatValue() { return _value.floatValue(); }
@Override
public double
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> doubleValue() { return _value.doubleValue(); }
@Override
public BigDecimal decimalValue() { return new BigDecimal(_value); }
/*
/**********************************************************
/* General type coercions
/**********************************************************
*/
@Override
public String asText() {
return _value.toString();
}
@Override
public boolean asBoolean(boolean defaultValue) {
return !BigInteger.ZERO.equals(_value);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BigIntegerNode)) {
return false;
}
return ((BigIntegerNode) o)._value.equals(_value);
}
@Override
public int hashCode() {
return _value.hashCode();
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* Simple helper class used to keep track of collection of
* Jackson Annotations associated with annotatable things
* (methods, constructors, classes).
* Note that only Jackson-owned annotations are tracked (for now?).
*/
public final class AnnotationMap implements Annotations
{
protected HashMap<Class<? extends Annotation>,Annotation> _annotations;
public AnnotationMap() { }
private AnnotationMap(HashMap<Class<? extends Annotation>,Annotation> a) {
_annotations = a;
}
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A get(Class<A> cls)
{
if (_annotations == null) {
return null;
}
return (A) _annotations.get(cls);
}
/**
* @since 2.3
*/
public Iterable<Annotation> annotations() {
if (_annotations == null || _annotations.size() == 0) {
return Collections.emptyList();
}
return _annotations.values();
}
public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
{
if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
return secondary;
}
if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
return primary;
}
HashMap<Class<? extends Annotation>,Annotation> annotations
= new HashMap<Class<? extends Annotation>,Annotation>();
// add secondary ones first
for (Annotation ann : secondary._annotations.values()) {
annotations.put(ann.annotationType(), ann);
}
// to be overridden by primary ones
for (Annotation ann : primary._annotations.values()) {
annotations.put(ann.annotationType(), ann);
}
return new AnnotationMap(annotations);
}
@Override
public int size() {
return (_annotations == null) ? 0 : _annotations.size();
}
/**
* Method called to add specified annotation in the Map, but
* only if it didn't yet exist.
*/
public boolean addIfNotPresent(Annotation ann)
{
if (_annotations == null || !_annotations.containsKey(
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>ann.annotationType())) {
_add(ann);
return true;
}
return false;
}
/**
* Method called to add specified annotation in the Map.
*
* @return True if the addition changed the contents, that is, this map did not
* already have specified annotation
*/
public boolean add(Annotation ann) {
return _add(ann);
}
@Override
public String toString() {
if (_annotations == null) {
return "[null]";
}
return _annotations.toString();
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected final boolean _add(Annotation ann) {
if (_annotations == null) {
_annotations = new HashMap<Class<? extends Annotation>,Annotation>();
}
Annotation previous = _annotations.put(ann.annotationType(), ann);
return (previous == null) || !previous.equals(ann);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
return result;
}
public final static class CollectionReferringAccumulator {
private final Class<?> _elementType;
private final Collection<Object> _result;
/**
* A list of {@link CollectionReferring} to maintain ordering.
*/
private List<CollectionReferring> _accumulator = new ArrayList<CollectionReferring>();
public CollectionReferringAccumulator(Class<?> elementType, Collection<Object> result) {
_elementType = elementType;
_result = result;
}
public void add(Object value)
{
if (_accumulator.isEmpty()) {
_result.add(value);
} else {
CollectionReferring ref = _accumulator.get(_accumulator.size() - 1);
ref.next.add(value);
}
}
public Referring handleUnresolvedReference(UnresolvedForwardReference reference)
{
CollectionReferring id = new CollectionReferring(this, reference, _elementType);
_accumulator.add(id);
return id;
}
public void resolveForwardReference(Object id, Object value) throws IOException
{
Iterator<CollectionReferring> iterator = _accumulator.iterator();
// Resolve ordering after resolution of an id. This mean either:
// 1- adding to the result collection in case of the first unresolved id.
// 2- merge the content of the resolved id with its previous unresolved id.
Collection<Object> previous = _result;
while (iterator.hasNext()) {
CollectionReferring ref = iterator.next();
if (ref.hasId(id)) {
iterator.remove();
previous.add(value);
previous.addAll(ref.next);
return;
}
previous = ref.next;
}
throw new IllegalArgumentException("Trying to resolve a forward reference with id [" + id
+ "] that wasn't previously seen as unresolved.");
}
}
/**
* Helper class to maintain processing order of value. The resolved
* object associated with {@link #_id} comes before the values in
* {@link #next}.
*/
private final static class CollectionReferring extends Referring {
private final CollectionReferringAccumulator _parent;
public final List<Object> next = new ArrayList<Object>();
CollectionReferring(CollectionReferringAccumulator parent,
UnresolvedForwardReference reference, Class<?> contentType)
{
super(reference
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS><?> vchecker = config.getDefaultVisibilityChecker();
vchecker = intr.findAutoDetectVisibility(beanDesc.getClassInfo(), vchecker);
/* 24-Sep-2014, tatu: Tricky part first; need to merge resolved property information
* (which has creator parameters sprinkled around) with actual creator
* declarations (which are needed to access creator annotation, amongst other things).
* Easiest to combine that info first, then pass it to remaining processing.
*/
/* 15-Mar-2015, tatu: Alas, this won't help with constructors that only have implicit
* names. Those will need to be resolved later on.
*/
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorDefs = _findCreatorsFromProperties(ctxt,
beanDesc);
/* Important: first add factory methods; then constructors, so
* latter can override former!
*/
_addDeserializerFactoryMethods(ctxt, beanDesc, vchecker, intr, creators, creatorDefs);
// constructors only usable on concrete types:
if (beanDesc.getType().isConcrete()) {
_addDeserializerConstructors(ctxt, beanDesc, vchecker, intr, creators, creatorDefs);
}
return creators.constructValueInstantiator(config);
}
protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(DeserializationContext ctxt,
BeanDescription beanDesc) throws JsonMappingException
{
Map<AnnotatedWithParams,BeanPropertyDefinition[]> result = Collections.emptyMap();
for (BeanPropertyDefinition propDef : beanDesc.findProperties()) {
Iterator<AnnotatedParameter> it = propDef.getConstructorParameters();
while (it.hasNext()) {
AnnotatedParameter param = it.next();
AnnotatedWithParams owner = param.getOwner();
BeanPropertyDefinition[] defs = result.get(owner);
final int index = param.getIndex();
if (defs == null) {
if (result.isEmpty()) { // since emptyMap is immutable need to create a 'real' one
result = new LinkedHashMap<AnnotatedWithParams,BeanPropertyDefinition[]>();
}
defs = new BeanPropertyDefinition[owner.getParameterCount()];
result.put(owner, defs);
} else {
if (defs[index] != null) {
throw
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>[i];
Object injectId = intr.findInjectableValueId(param);
final PropertyName name = (propDef == null) ? null : propDef.getFullName();
if (propDef != null && propDef.isExplicitlyNamed()) {
++explicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (injectId != null) {
++injectCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param);
if (unwrapper != null) {
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++explicitNameCount;
continue;
}
// One more thing: implicit names are ok iff ctor has creator annotation
if (isCreator && (name != null && !name.isEmpty())) {
++implicitWithCreatorCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (nonAnnotatedParam == null) {
nonAnnotatedParam = param;
}
}
final int namedCount = explicitNameCount + implicitWithCreatorCount;
// Ok: if named or injectable, we have more work to do
if (isCreator || (explicitNameCount > 0) || (injectCount > 0)) {
// simple case; everything covered:
if ((namedCount + injectCount) == argCount) {
creators.addPropertyCreator(ctor, isCreator, properties);
continue;
}
if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
// Secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(ctor, isCreator, properties);
continue;
}
// otherwise, epic fail?
// 16-Mar-2015, tatu: due to [#725], need to be more permissive. For now let's
// only report problem if there's no implicit name
PropertyName impl = _find
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>ImplicitParamName(nonAnnotatedParam, intr);
if (impl == null || impl.isEmpty()) {
// Let's consider non-static inner class as a special case...
int ix = nonAnnotatedParam.getIndex();
if ((ix == 0) && ClassUtil.isNonStaticInnerClass(ctor.getDeclaringClass())) {
throw new IllegalArgumentException("Non-static inner classes like "
+ctor.getDeclaringClass().getName()+" can not use @JsonCreator for constructors");
}
throw new IllegalArgumentException("Argument #"+ix
+" of constructor "+ctor+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
}
}
// [#725]: as a fallback, all-implicit names may work as well
if (!creators.hasDefaultCreator()) {
if (implicitCtors == null) {
implicitCtors = new LinkedList<AnnotatedConstructor>();
}
implicitCtors.add(ctor);
}
}
// last option, as per [#725]: consider implicit-names-only, visible constructor,
// if just one found
if ((implicitCtors != null) && !creators.hasDelegatingCreator()
&& !creators.hasPropertyBasedCreator()) {
_checkImplicitlyNamedConstructors(ctxt, beanDesc, vchecker, intr,
creators, implicitCtors);
}
}
protected void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
BeanDescription beanDesc, VisibilityChecker<?> vchecker,
AnnotationIntrospector intr, CreatorCollector creators,
List<AnnotatedConstructor> implicitCtors) throws JsonMappingException
{
AnnotatedConstructor found = null;
CreatorProperty[] foundProps = null;
// Further checks: (a) must have names for all parameters, (b) only one visible
// Also, since earlier matching of properties and creators relied on existence of
// `@JsonCreator` (or equivalent) annotation, we need to do bit more re-inspection...
main_loop:
for (AnnotatedConstructor ctor : implicitCtors) {
if (!vchecker.isCreatorVisible(ctor)) {
continue;
}
// as per earlier notes, only end up here if no properties associated with creator
final int argCount = ctor.getParameterCount();
CreatorProperty[] properties = new CreatorProperty[argCount];
for
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = ctor.getParameter(i);
final PropertyName name = _findParamName(param, intr);
// must have name (implicit fine)
if (name == null || name.isEmpty()) {
continue main_loop;
}
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, param.getIndex(),
param, /*injectId*/ null);
}
if (found != null) { // only one allowed
found = null;
break;
}
found = ctor;
foundProps = properties;
}
// found one and only one visible? Ship it!
if (found != null) {
creators.addPropertyCreator(found, /*isCreator*/ false, foundProps);
BasicBeanDescription bbd = (BasicBeanDescription) beanDesc;
// Also: add properties, to keep error messages complete wrt known properties...
for (CreatorProperty prop : foundProps) {
PropertyName pn = prop.getFullName();
if (!bbd.hasProperty(pn)) {
BeanPropertyDefinition newDef = SimpleBeanPropertyDefinition.construct(
ctxt.getConfig(), prop.getMember(), pn);
bbd.addProperty(newDef);
}
}
}
}
protected boolean _checkIfCreatorPropertyBased(AnnotationIntrospector intr,
AnnotatedWithParams creator, BeanPropertyDefinition propDef)
{
JsonCreator.Mode mode = intr.findCreatorBinding(creator);
if (mode == JsonCreator.Mode.PROPERTIES) {
return true;
}
if (mode == JsonCreator.Mode.DELEGATING) {
return false;
}
// If explicit name, or inject id, property-based
if (((propDef != null) && propDef.isExplicitlyNamed())
|| (intr.findInjectableValueId(creator.getParameter(0)) != null)) {
return true;
}
if (propDef != null) {
// One more thing: if implicit name matches property with a getter
// or field, we'll consider it property-based as well
String implName = propDef.getName();
if (implName != null && !implName.isEmpty()) {
if (propDef.couldSerialize()) {
return true;
}
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>WRAPPED_CREATOR_PARAM_NAME, i, param, null);
++implicitNameCount;
continue;
}
// One more thing: implicit names are ok iff ctor has creator annotation
if (isCreator) {
if (name != null && !name.isEmpty()) {
++implicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
}
/* 25-Sep-2014, tatu: Actually, we may end up "losing" naming due to higher-priority constructor
* (see TestCreators#testConstructorCreator() test). And just to avoid running into that problem,
* let's add one more work around
*/
/*
PropertyName name2 = _findExplicitParamName(param, intr);
if (name2 != null && !name2.isEmpty()) {
// Hmmh. Ok, fine. So what are we to do with it... ?
// For now... skip. May need to revisit this, should this become problematic
continue main_loop;
}
*/
if (nonAnnotatedParam == null) {
nonAnnotatedParam = param;
}
}
final int namedCount = explicitNameCount + implicitNameCount;
// Ok: if named or injectable, we have more work to do
if (isCreator || explicitNameCount > 0 || injectCount > 0) {
// simple case; everything covered:
if ((namedCount + injectCount) == argCount) {
creators.addPropertyCreator(factory, isCreator, properties);
} else if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
// [712] secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(factory, isCreator, properties);
} else { // otherwise, epic fail
throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex()
+" of factory method "+factory+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
}
}
}
}
protected boolean _handleSingleArgumentFactory(DeserializationConfig config,
BeanDescription beanDesc, VisibilityChecker<?> vchecker,
AnnotationIntrospector intr, CreatorCollector
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>ImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
return PropertyName.construct(str);
}
}
return null;
}
protected PropertyName _findImplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
String str = intr.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
return PropertyName.construct(str);
}
return null;
}
@Deprecated // in 2.6, remove from 2.7
protected PropertyName _findExplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
if (param != null && intr != null) {
return intr.findNameForDeserialization(param);
}
return null;
}
@Deprecated // in 2.6, remove from 2.7
protected boolean _hasExplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
if (param != null && intr != null) {
PropertyName n = intr.findNameForDeserialization(param);
return (n != null) && n.hasSimpleName();
}
return false;
}
/*
/**********************************************************
/* JsonDeserializerFactory impl: array deserializers
/**********************************************************
*/
@Override
public JsonDeserializer<?> createArrayDeserializer(DeserializationContext ctxt,
ArrayType type, final BeanDescription beanDesc)
throws JsonMappingException
{
final DeserializationConfig config = ctxt.getConfig();
JavaType elemType = type.getContentType();
// Very first thing: is deserializer hard-coded for elements?
JsonDeserializer<Object> contentDeser = elemType.getValueHandler();
// Then optional type info: if type has been resolved, we may already know type deserializer:
TypeDeserializer elemTypeDeser = elemType.getTypeHandler();
// but if not, may still be possible to find:
if (elemTypeDeser == null) {
elemTypeDeser = findTypeDeserializer(config, elemType);
}
// 23-Nov-2010, tatu: Custom array deserializer?
JsonDeserializer<?> deser = _findCustomArrayDeserializer(type,
config, beanDesc, elemTypeDeser, contentDeser);
if (deser == null) {
if (contentDeser == null) {
Class
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> double asDouble(double defaultValue)
{
if (_value instanceof Number) {
return ((Number) _value).doubleValue();
}
return defaultValue;
}
/*
/**********************************************************
/* Public API, serialization
/**********************************************************
*/
@Override
public final void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException
{
if (_value == null) {
serializers.defaultSerializeNull(gen);
} else if (_value instanceof JsonSerializable) {
((JsonSerializable) _value).serialize(gen, serializers);
} else {
gen.writeObject(_value);
}
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method that can be used to access the POJO this node wraps.
*/
public Object getPojo() { return _value; }
/*
/**********************************************************
/* Overridden standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof POJONode) {
return _pojoEquals((POJONode) o);
}
return false;
}
/**
* @since 2.3
*/
protected boolean _pojoEquals(POJONode other)
{
if (_value == null) {
return other._value == null;
}
return _value.equals(other._value);
}
@Override
public int hashCode() { return _value.hashCode(); }
@Override
public String toString()
{
// [databind#743]: Let's try indicating content type, for debugging purposes
if (_value instanceof byte[]) {
return String.format("(binary value of %d bytes)", ((byte[]) _value).length);
}
if (_value instanceof RawValue) {
return String.format("(raw value '%s')", ((RawValue) _value).toString());
}
return String.valueOf(_value);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.util.Iterator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.util.EmptyIterator;
import com.fasterxml.jackson.databind.util.Named;
/**
* Simple value classes that contain definitions of properties,
* used during introspection of properties to use for
* serialization and deserialization purposes.
* These instances are created before actual {@link BeanProperty}
* instances are created, i.e. they are used earlier in the process
* flow, and are typically use to construct actual
* {@link BeanProperty} instances.
*/
public abstract class BeanPropertyDefinition
implements Named
{
/*
/**********************************************************
/* Fluent factory methods for creating modified copies
/**********************************************************
*/
/**
* Method that can be used to create a definition with
* same settings as this one, but with different
* (external) name; that is, one for which
* {@link #getName()} would return <code>newName</code>.
*
* @since 2.3
*/
public abstract BeanPropertyDefinition withName(PropertyName newName);
/**
* Alternate "mutant factory" that will only change simple name, but
* leave other optional parts (like namespace) as is.
*
* @since 2.3
*/
public abstract BeanPropertyDefinition withSimpleName(String newSimpleName);
/*
/**********************************************************
/* Basic property information, name, type
/**********************************************************
*/
/**
* Accessor for name used for external representation (in JSON).
*/
@Override // from Named
public abstract String getName();
public abstract PropertyName getFullName();
/**
* @since 2.6
*/
public boolean hasName(PropertyName name) {
return getFullName().equals(name);
}
/**
* Accessor that can be used to determine implicit name from underlying
* element(s) before possible renaming. This is the "internal"
* name derived from accessor ("x" from "getX"), and is not based on
* annotations or naming strategy.
*/
public abstract String getInternalName();
/**
* Accessor for finding wrapper name to use for property (if any).
*
* @since
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
/**
* This is the special serializer for regular {@link java.lang.String}s.
*<p>
* Since this is one of "native" types, no type information is ever
* included on serialization (unlike for most scalar types as of 1.5)
*/
@JacksonStdImpl
public final class StringSerializer
// NOTE: generic parameter changed from String to Object in 2.6, to avoid
// use of bridge methods
extends NonTypedScalarSerializerBase<Object>
{
private static final long serialVersionUID = 1L;
public StringSerializer() { super(String.class, false); }
/**
* For Strings, both null and Empty String qualify for emptiness.
*/
@Override
@Deprecated
public boolean isEmpty(Object value) {
String str = (String) value;
return (str == null) || (str.length() == 0);
}
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
String str = (String) value;
return (str == null) || (str.length() == 0);
}
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString((String) value);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
if (visitor != null) visitor.expectStringFormat(typeHint);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> deserializers won't
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _elementDeserializer.getNullValue(ctxt);
} else if (typeDeser == null) {
value = _elementDeserializer.deserialize(jp, ctxt);
} else {
value = _elementDeserializer.deserializeWithType(jp, ctxt, typeDeser);
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);
}
Object[] result;
if (_untyped) {
result = buffer.completeAndClearBuffer(chunk, ix);
} else {
result = buffer.completeAndClearBuffer(chunk, ix, _elementClass);
}
ctxt.returnObjectBuffer(buffer);
return result;
}
@Override
public Object[] deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException, JsonProcessingException
{
/* Should there be separate handling for base64 stuff?
* for now this should be enough:
*/
return (Object[]) typeDeserializer.deserializeTypedFromArray(jp, ctxt);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected Byte[] deserializeFromBase64(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// First same as what PrimitiveArrayDeserializers.ByteDeser does:
byte[] b = jp.getBinaryValue(ctxt.getBase64Variant());
// But then need to convert to wrappers
Byte[] result = new Byte[b.length];
for (int i = 0, len = b.length; i < len; ++i) {
result[i] = Byte.valueOf(b[i]);
}
return result;
}
private final Object[] handleNonArray(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
// [JACKSON-620] Empty String can become null...
if ((jp.getCurrentToken() == JsonToken.VALUE_STRING)
&& ctxt.isEnabled(DeserializationFeature.ACCEPT
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Override
public CollectionSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new CollectionSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, Collection<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(Collection<?> value) {
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return false;
}
it.next();
return !it.hasNext();
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, jgen, provider);
return;
}
}
jgen.writeStartArray(len);
serializeContents(value, jgen, provider);
jgen.writeEndArray();
}
@Override
public void serializeContents(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return;
}
PropertySerializerMap serializers = _dynamicSerializers;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
try {
do {
Object elem = it.next();
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
@SuppressWarnings("serial")
public class EnumSetSerializer
extends AsArraySerializerBase<EnumSet<? extends Enum<?>>>
{
/**
* @since 2.6
*/
public EnumSetSerializer(JavaType elemType) {
super(EnumSet.class, elemType, true, null, null);
}
/**
* @deprecated since 2.6
*/
@Deprecated // since 2.6
public EnumSetSerializer(JavaType elemType, BeanProperty property) {
this(elemType);
}
public EnumSetSerializer(EnumSetSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public EnumSetSerializer _withValueTypeSerializer(TypeSerializer vts) {
// no typing for enums (always "hard" type)
return this;
}
@Override
public EnumSetSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer<?> elementSerializer,
Boolean unwrapSingle) {
return new EnumSetSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
@Override
public boolean isEmpty(SerializerProvider prov, EnumSet<? extends Enum<?>> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(EnumSet<? extends Enum<?>> value) {
return value.size() == 1;
}
@Override
public final void serialize(EnumSet<? extends Enum<?>> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null)
&& provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
/**********************************************************
*/
@Override
public int getParameterCount() {
return _constructor.getParameterTypes().length;
}
@Override
public Class<?> getRawParameterType(int index)
{
Class<?>[] types = _constructor.getParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public Type getGenericParameterType(int index)
{
Type[] types = _constructor.getGenericParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public final Object call() throws Exception {
return _constructor.newInstance();
}
@Override
public final Object call(Object[] args) throws Exception {
return _constructor.newInstance(args);
}
@Override
public final Object call1(Object arg) throws Exception {
return _constructor.newInstance(arg);
}
/*
/**********************************************************
/* AnnotatedMember impl
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() { return _constructor.getDeclaringClass(); }
@Override
public Member getMember() { return _constructor; }
@Override
public void setValue(Object pojo, Object value)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call setValue() on constructor of "
+getDeclaringClass().getName());
}
@Override
public Object getValue(Object pojo)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call getValue() on constructor of "
+getDeclaringClass().getName());
}
/*
/**********************************************************
/* Extended API, specific annotations
/**********************************************************
*/
@Override
public String toString() {
return "[constructor for "+getName()+", annotations: "+_annotations+"]";
}
@Override
public int hashCode() {
return _constructor.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedConstructor) o)._constructor == _constructor;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedConstructor(new Serialization(_constructor));
}
Object readResolve() {
Class<?> clazz = _serialization.
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>(schema);
return _new(this, _config, _valueType, _rootDeserializer, _valueToUpdate,
schema, _injectableValues, _dataFormatReaders);
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(JavaType valueType)
{
if (valueType != null && valueType.equals(_valueType)) {
return this;
}
JsonDeserializer<Object> rootDeser = _prefetchRootDeserializer(valueType);
// type is stored here, no need to make a copy of config
DataFormatReaders det = _dataFormatReaders;
if (det != null) {
det = det.withType(valueType);
}
return _new(this, _config, valueType, rootDeser,
_valueToUpdate, _schema, _injectableValues, det);
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* @deprecated since 2.5 Use {@link #forType(JavaType)} instead
*/
@Deprecated
public ObjectReader withType(JavaType valueType) {
return forType(valueType);
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> }
// Need to consume the token too
p.clearCurrentToken();
return result;
}
/**
* @since 2.1
*/
protected <T> MappingIterator<T> _bindAndReadValues(JsonParser p) throws IOException
{
_initForMultiRead(p);
p.nextToken();
DeserializationContext ctxt = createDeserializationContext(p);
return _newIterator(p, ctxt, _findRootDeserializer(ctxt), true);
}
protected Object _unwrapAndDeserialize(JsonParser p, DeserializationContext ctxt,
JavaType rootType, JsonDeserializer<Object> deser) throws IOException
{
PropertyName expRootName = _config.findRootName(rootType);
// 12-Jun-2015, tatu: Should try to support namespaces etc but...
String expSimpleName = expRootName.getSimpleName();
if (p.getCurrentToken() != JsonToken.START_OBJECT) {
throw JsonMappingException.from(p, "Current token not START_OBJECT (needed to unwrap root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
if (p.nextToken() != JsonToken.FIELD_NAME) {
throw JsonMappingException.from(p, "Current token not FIELD_NAME (to contain expected root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
String actualName = p.getCurrentName();
if (!expSimpleName.equals(actualName)) {
throw JsonMappingException.from(p, "Root name '"+actualName+"' does not match expected ('"
+expSimpleName+"') for type "+rootType);
}
// ok, then move to value itself....
p.nextToken();
Object result;
if (_valueToUpdate == null) {
result = deser.deserialize(p, ctxt);
} else {
deser.deserialize(p, ctxt, _valueToUpdate);
result = _valueToUpdate;
}
// and last, verify that we now get matching END_OBJECT
if (p.nextToken() != JsonToken.END_OBJECT) {
throw JsonMappingException.from(p, "Current token not END_OBJECT (to match wrapper object with root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
return result;
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
if (provider.isEnabled(MapperFeature.USE_STATIC_TYPING)
|| Modifier.isFinal(_accessorMethod.getReturnType().getModifiers())) {
JavaType t = provider.constructType(_accessorMethod.getGenericReturnType());
// false -> no need to cache
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.findPrimaryPropertySerializer(t, property);
/* 09-Dec-2010, tatu: Turns out we must add special handling for
* cases where "native" (aka "natural") type is being serialized,
* using standard serializer
*/
boolean forceTypeInformation = isNaturalTypeWithStdHandling(t.getRawClass(), ser);
return withResolved(property, ser, forceTypeInformation);
}
} else {
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.handlePrimaryContextualization(ser, property);
return withResolved(property, ser, _forceTypeInformation);
}
return this;
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(Object bean, JsonGenerator jgen, SerializerProvider prov) throws IOException
{
try {
Object value = _accessorMethod.invoke(bean);
if (value == null) {
prov.defaultSerializeNull(jgen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
Class<?> c = value.getClass();
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// let's cache it, may be needed soon again
ser = prov.findTypedValueSerializer(c, true, _property);
}
ser.serialize(value, jgen,
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> prov);
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
// Need to unwrap this specific type, to see infinite recursion...
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors shouldn't be wrapped (and often can't, as well)
if (t instanceof Error) {
throw (Error) t;
}
// let's try to indicate the path best we can...
throw JsonMappingException.wrapWithPath(t, bean, _accessorMethod.getName() + "()");
}
}
@Override
public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer0) throws IOException
{
// Regardless of other parts, first need to find value to serialize:
Object value = null;
try {
value = _accessorMethod.invoke(bean);
// and if we got null, can also just write it directly
if (value == null) {
provider.defaultSerializeNull(jgen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) { // already got a serializer? fabulous, that be easy...
// ser = provider.findTypedValueSerializer(value.getClass(), true, _property);
ser = provider.findValueSerializer(value.getClass(), _property);
} else {
/* 09-Dec-2010, tatu: To work around natural type's refusal to add type info, we do
* this (note: type is for the wrapper type, not enclosed value!)
*/
if (_forceTypeInformation) {
typeSer0.writeTypePrefixForScalar(bean, jgen);
ser.serialize(value, jgen, provider);
typeSer0.writeTypeSuffixForScalar(bean, jgen);
return;
}
}
/* 13-Feb-2013, tatu: Turns out that work-around should NOT be required
* at all; it would not lead to correct behavior (as per #167).
*/
// and then redirect type id lookups
// TypeSerializer typeSer = new TypeSerializerWrapper(typeSer
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>.getProvider().findTypedValueSerializer(typeHint, false, _property);
if (ser == null) {
visitor.expectAnyFormat(typeHint);
return;
}
}
ser.acceptJsonFormatVisitor(visitor, null);
}
/**
* Overridable helper method used for special case handling of schema information for
* Enums
*
* @return True if method handled callbacks; false if not; in latter case caller will
* send default callbacks
*
* @since 2.6
*/
protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor,
JavaType typeHint, Class<?> enumType)
throws JsonMappingException
{
// Copied from EnumSerializer#acceptJsonFormatVisitor
JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint);
if (stringVisitor != null) {
Set<String> enums = new LinkedHashSet<String>();
for (Object en : enumType.getEnumConstants()) {
try {
enums.add(String.valueOf(_accessorMethod.invoke(en)));
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, en, _accessorMethod.getName() + "()");
}
}
stringVisitor.enumTypes(enums);
}
return true;
}
protected boolean isNaturalTypeWithStdHandling(Class<?> rawType, JsonSerializer<?> ser)
{
// First: do we have a natural type being handled?
if (rawType.isPrimitive()) {
if (rawType != Integer.TYPE && rawType != Boolean.TYPE && rawType != Double.TYPE) {
return false;
}
} else {
if (rawType != String.class &&
rawType != Integer.class && rawType != Boolean.class && rawType != Double.class) {
return false;
}
}
return isDefaultSerializer(ser);
}
/*
/**********************************************************
/* Other methods
/**********************************************************
*/
@Override
public String toString() {
return "(@JsonValue serializer for method " + _accessorMethod.getDeclaring
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.type.ReferenceType;
// Since 2.6 in its own class
public class AtomicReferenceSerializer
extends StdSerializer<AtomicReference<?>>
{
private static final long serialVersionUID = 1L;
/**
* @deprecated Since 2.6
*/
@Deprecated
public AtomicReferenceSerializer() { super(AtomicReference.class, false); }
public AtomicReferenceSerializer(ReferenceType type) {
super(type);
}
@Override
public boolean isEmpty(SerializerProvider provider, AtomicReference<?> value) {
return (value == null) || (value.get() == null);
}
@Override
public void serialize(AtomicReference<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
provider.defaultSerializeValue(value.get(), jgen);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("any", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitor.expectAnyFormat(typeHint);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> iterate over all the annotations
* associated with annotated component.
*
* @since 2.3
*/
public abstract Iterable<Annotation> annotations();
/**
* Internal helper method used to access annotation information;
* not exposed to developers since instances are mutable.
*/
protected abstract AnnotationMap getAllAnnotations();
// Also: ensure we can use #equals, #hashCode
@Override
public abstract boolean equals(Object o);
@Override
public abstract int hashCode();
@Override
public abstract String toString();
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Type
+" (need to add/enable type information?)");
}
boolean hasStringCreator = _valueInstantiator.canCreateFromString();
boolean hasDefaultCtor = _valueInstantiator.canCreateUsingDefault();
// and finally, verify we do have single-String arg constructor (if no @JsonCreator)
if (!hasStringCreator && !hasDefaultCtor) {
throw new JsonMappingException("Can not deserialize Throwable of type "+_beanType
+" without having a default contructor, a single-String-arg constructor; or explicit @JsonCreator");
}
Object throwable = null;
Object[] pending = null;
int pendingIx = 0;
for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
String propName = jp.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
jp.nextToken(); // to point to field value
if (prop != null) { // normal case
if (throwable != null) {
prop.deserializeAndSet(jp, ctxt, throwable);
continue;
}
// nope; need to defer
if (pending == null) {
int len = _beanProperties.size();
pending = new Object[len + len];
}
pending[pendingIx++] = prop;
pending[pendingIx++] = prop.deserialize(jp, ctxt);
continue;
}
// Maybe it's "message"?
if (PROP_NAME_MESSAGE.equals(propName)) {
if (hasStringCreator) {
throwable = _valueInstantiator.createFromString(ctxt, jp.getText());
// any pending values?
if (pending != null) {
for (int i = 0, len = pendingIx; i < len; i += 2) {
prop = (SettableBeanProperty)pending[i];
prop.set(throwable, pending[i+1]);
}
pending = null;
}
continue;
}
}
/* As per [JACKSON-313], things marked as ignorable should not be
* passed to any setter
*/
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
jp.skipChildren();
continue;
}
if (_anySetter != null) {
_anySetter.deserializeAndSet(
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.util.RawValue;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
/**
* Node that maps to JSON Object structures in JSON content.
*<p>
* Note: class was <code>final</code> temporarily for Jackson 2.2.
*/
public class ObjectNode
extends ContainerNode<ObjectNode>
{
// Note: LinkedHashMap for backwards compatibility
protected final Map<String, JsonNode> _children;
public ObjectNode(JsonNodeFactory nc) {
super(nc);
_children = new LinkedHashMap<String, JsonNode>();
}
/**
* @since 2.4
*/
public ObjectNode(JsonNodeFactory nc, Map<String, JsonNode> kids) {
super(nc);
_children = kids;
}
@Override
protected JsonNode _at(JsonPointer ptr) {
return get(ptr.getMatchingProperty());
}
/* Question: should this delegate to `JsonNodeFactory`? It does not absolutely
* have to, as long as sub-types override the method but...
*/
// note: co-variant for type safety
@SuppressWarnings("unchecked")
@Override
public ObjectNode deepCopy()
{
ObjectNode ret = new ObjectNode(_nodeFactory);
for (Map.Entry<String, JsonNode> entry: _children.entrySet())
ret._children.put(entry.getKey(), entry.getValue().deepCopy());
return ret;
}
/*
/**********************************************************
/* Overrides for JsonSerializable.Base
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider serializers) {
return _children.isEmpty();
}
/*
/**********************************************************
/* Implementation of core JsonNode API
/**********************************************************
*/
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.OBJECT;
}
@Override public JsonToken asToken() { return JsonToken.START_OBJECT; }
@Override
public int size() {
return _children.size();
}
@Override
public Iterator<JsonNode> elements() {
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
return _children.values().iterator();
}
@Override
public JsonNode get(int index) { return null; }
@Override
public JsonNode get(String fieldName) {
return _children.get(fieldName);
}
@Override
public Iterator<String> fieldNames() {
return _children.keySet().iterator();
}
@Override
public JsonNode path(int index) {
return MissingNode.getInstance();
}
@Override
public JsonNode path(String fieldName)
{
JsonNode n = _children.get(fieldName);
if (n != null) {
return n;
}
return MissingNode.getInstance();
}
/**
* Method to use for accessing all fields (with both names
* and values) of this JSON Object.
*/
@Override
public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
}
@Override
public ObjectNode with(String propertyName) {
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ObjectNode) {
return (ObjectNode) n;
}
throw new UnsupportedOperationException("Property '" + propertyName
+ "' has value that is not of type ObjectNode (but " + n
.getClass().getName() + ")");
}
ObjectNode result = objectNode();
_children.put(propertyName, result);
return result;
}
@Override
public ArrayNode withArray(String propertyName)
{
JsonNode n = _children.get(propertyName);
if (n != null) {
if (n instanceof ArrayNode) {
return (ArrayNode) n;
}
throw new UnsupportedOperationException("Property '" + propertyName
+ "' has value that is not of type ArrayNode (but " + n
.getClass().getName() + ")");
}
ArrayNode result = arrayNode();
_children.put(propertyName, result);
return result;
}
@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
if (!(o instanceof ObjectNode)) {
return false;
}
ObjectNode other = (ObjectNode) o;
Map<String, JsonNode> m1 = _children;
Map<String, JsonNode> m2 = other._children;
final int len = m1.size();
if (m2
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>.size() != len) {
return false;
}
for (Map.Entry<String, JsonNode> entry : m1.entrySet()) {
JsonNode v2 = m2.get(entry.getKey());
if ((v2 == null) || comparator.compare(entry.getValue(), v2) != 0) {
return false;
}
}
return true;
}
/*
/**********************************************************
/* Public API, finding value nodes
/**********************************************************
*/
@Override
public JsonNode findValue(String fieldName)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
return entry.getValue();
}
JsonNode value = entry.getValue().findValue(fieldName);
if (value != null) {
return value;
}
}
return null;
}
@Override
public List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
if (foundSoFar == null) {
foundSoFar = new ArrayList<JsonNode>();
}
foundSoFar.add(entry.getValue());
} else { // only add children if parent not added
foundSoFar = entry.getValue().findValues(fieldName, foundSoFar);
}
}
return foundSoFar;
}
@Override
public List<String> findValuesAsText(String fieldName, List<String> foundSoFar)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
if (foundSoFar == null) {
foundSoFar = new ArrayList<String>();
}
foundSoFar.add(entry.getValue().asText());
} else { // only add children if parent not added
foundSoFar = entry.getValue().findValuesAsText(fieldName,
foundSoFar);
}
}
return foundSoFar;
}
@Override
public ObjectNode findParent(String fieldName)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>
return this;
}
JsonNode value = entry.getValue().findParent(fieldName);
if (value != null) {
return (ObjectNode) value;
}
}
return null;
}
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
if (fieldName.equals(entry.getKey())) {
if (foundSoFar == null) {
foundSoFar = new ArrayList<JsonNode>();
}
foundSoFar.add(this);
} else { // only add children if parent not added
foundSoFar = entry.getValue()
.findParents(fieldName, foundSoFar);
}
}
return foundSoFar;
}
/*
/**********************************************************
/* Public API, serialization
/**********************************************************
*/
/**
* Method that can be called to serialize this node and
* all of its descendants using specified JSON generator.
*/
@Override
public void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeStartObject();
for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
jg.writeFieldName(en.getKey());
/* 17-Feb-2009, tatu: Can we trust that all nodes will always
* extend BaseJsonNode? Or if not, at least implement
* JsonSerializable? Let's start with former, change if
* we must.
*/
((BaseJsonNode) en.getValue()).serialize(jg, provider);
}
jg.writeEndObject();
}
@Override
public void serializeWithType(JsonGenerator jg, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
typeSer.writeTypePrefixForObject(this, jg);
for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
jg.writeFieldName(en.getKey());
((BaseJsonNode) en.getValue()).serialize(jg, provider);
}
typeSer.writeTypeSuffixForObject(this, jg);
}
/*
/**********************************************************
/* Extended ObjectNode API, mutators, since 2.1
/********************************************************
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> * @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, String v) {
return _put(fieldName, (v == null) ? nullNode()
: textNode(v));
}
/**
* Method for setting value of a field to specified String value.
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, boolean v) {
return _put(fieldName, booleanNode(v));
}
/**
* Alternative method that we need to avoid bumping into NPE issues
* with auto-unboxing.
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, Boolean v) {
return _put(fieldName, (v == null) ? nullNode()
: booleanNode(v.booleanValue()));
}
/**
* Method for setting value of a field to specified binary value
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, byte[] v) {
return _put(fieldName, (v == null) ? nullNode()
: binaryNode(v));
}
/*
/**********************************************************
/* Standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof ObjectNode) {
return _childrenEqual((ObjectNode) o);
}
return false;
}
/**
* @since 2.3
*/
protected boolean _childrenEqual(ObjectNode other)
{
return _children.equals(other._children);
}
@Override
public int hashCode()
{
return _children.hashCode();
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(32 + (size() << 4));
sb.append("{");
int count = 0;
for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
if (count > 0) {
sb.append(",");
}
++count;
TextNode.appendQuoted(sb, en.getKey());
sb.append(':');
sb.append(en.getValue().toString());
}
sb.append
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains 64-bit ("double precision")
* floating point values simple 32-bit integer values.
*/
public class DoubleNode
extends NumericNode
{
protected final double _value;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
public DoubleNode(double v) { _value = v; }
public static DoubleNode valueOf(double v) { return new DoubleNode(v); }
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_FLOAT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.DOUBLE; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isFloatingPointNumber() { return true; }
@Override
public boolean isDouble() { return true; }
@Override public boolean canConvertToInt() {
return (_value >= Integer.MIN_VALUE && _value <= Integer.MAX_VALUE);
}
@Override public boolean canConvertToLong() {
return (_value >= Long.MIN_VALUE && _value <= Long.MAX_VALUE);
}
@Override
public Number numberValue() {
return Double.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return (int) _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
public double doubleValue() { return _value; }
@Override
public BigDecimal decimalValue() { return BigDecimal.valueOf(_value); }
@Override
public BigInteger bigIntegerValue() {
return decimalValue().toBigInteger();
}
@Override
public String asText() {
return
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> NumberOutput.toString(_value);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.writeNumber(_value);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof DoubleNode) {
// We must account for NaNs: NaN does not equal NaN, therefore we have
// to use Double.compare().
final double otherValue = ((DoubleNode) o)._value;
return Double.compare(_value, otherValue) == 0;
}
return false;
}
@Override
public int hashCode()
{
// same as hashCode Double.class uses
long l = Double.doubleToLongBits(_value);
return ((int) l) ^ (int) (l >> 32);
}
}
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS>Parser jp = asParser();
int count = 0;
final boolean hasNativeIds = _hasNativeTypeIds || _hasNativeObjectIds;
while (true) {
JsonToken t;
try {
t = jp.nextToken();
if (t == null) break;
if (hasNativeIds) {
_appendNativeIds(sb);
}
if (count < MAX_COUNT) {
if (count > 0) {
sb.append(", ");
}
sb.append(t.toString());
if (t == JsonToken.FIELD_NAME) {
sb.append('(');
sb.append(jp.getCurrentName());
sb.append(')');
}
}
} catch (IOException ioe) { // should never occur
throw new IllegalStateException(ioe);
}
++count;
}
if (count >= MAX_COUNT) {
sb.append(" ... (truncated ").append(count-MAX_COUNT).append(" entries)");
}
sb.append(']');
return sb.toString();
}
private final void _appendNativeIds(StringBuilder sb)
{
Object objectId = _last.findObjectId(_appendAt-1);
if (objectId != null) {
sb.append("[objectId=").append(String.valueOf(objectId)).append(']');
}
Object typeId = _last.findTypeId(_appendAt-1);
if (typeId != null) {
sb.append("[typeId=").append(String.valueOf(typeId)).append(']');
}
}
/*
/**********************************************************
/* JsonGenerator implementation: configuration
/**********************************************************
*/
@Override
public JsonGenerator enable(Feature f) {
_generatorFeatures |= f.getMask();
return this;
}
@Override
public JsonGenerator disable(Feature f) {
_generatorFeatures &= ~f.getMask();
return this;
}
//public JsonGenerator configure(SerializationFeature f, boolean state) { }
@Override
public boolean isEnabled(Feature f) {
return (_generatorFeatures & f.getMask()) != 0;
}
@Override
public int getFeatureMask() {
return _generatorFeatures;
}
@Override
public JsonGenerator setFeatureMask(int mask) {
_generatorFeatures = mask;
return
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> len) throws IOException {
if (offset > 0 || len != text.length()) {
text = text.substring(offset, offset+len);
}
_append(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(char[] text, int offset, int len) throws IOException {
_append(JsonToken.VALUE_EMBEDDED_OBJECT, new String(text, offset, len));
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, primitive types
/**********************************************************
*/
@Override
public void writeNumber(short i) throws IOException {
_append(JsonToken.VALUE_NUMBER_INT, Short.valueOf(i));
}
@Override
public void writeNumber(int i) throws IOException {
_append(JsonToken.VALUE_NUMBER_INT, Integer.valueOf(i));
}
@Override
public void writeNumber(long l) throws IOException {
_append(JsonToken.VALUE_NUMBER_INT, Long.valueOf(l));
}
@Override
public void writeNumber(double d) throws IOException {
_append(JsonToken.VALUE_NUMBER_FLOAT, Double.valueOf(d));
}
@Override
public void writeNumber(float f) throws IOException {
_append(JsonToken.VALUE_NUMBER_FLOAT, Float.valueOf(f));
}
@Override
public void writeNumber(BigDecimal dec) throws IOException {
if (dec == null) {
writeNull();
} else {
_append(JsonToken.VALUE_NUMBER_FLOAT, dec);
}
}
@Override
public void writeNumber(BigInteger v) throws IOException {
if (v == null) {
writeNull();
} else {
_append(JsonToken.VALUE_NUMBER_INT, v);
}
}
@Override
public void writeNumber(String encodedValue) throws IOException {
/* 03-Dec-2010, tatu: related to [JACKSON-423], should try to keep as numeric
* identity as long as possible
*/
_append(JsonToken.VALUE_NUMBER_FLOAT, encodedValue);
}
@Override
public void writeBoolean(boolean state) throws IOException {
_append(state ? Json
JacksonDatabind, 23
<FILEB>
<CHANGES>
protected final static Integer EMPTY_INTEGER = Integer.valueOf(0);
<CHANGEE>
<CHANGES>
private final static Short EMPTY = (short) 0;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Short value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY_INTEGER.equals(value);
}
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Number value) {
return value.intValue() == 0;
}
@Override
<CHANGEE>
<CHANGES>
private final static Long EMPTY = 0L;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Float EMPTY = 0f;
<CHANGEE>
<CHANGES>
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
@Override
<CHANGEE>
<CHANGES>
private final static Double EMPTY = 0d;
<CHANGEE>
<CHANGES>
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
return EMPTY.equals(value);
}
<CHANGEE>
<FILEE>
<FILEB>
allDeserializers.put(Byte.class.getName(), IntLikeSerializer.instance);
allDeserializers.put(Byte.TYPE.getName(), IntLikeSerializer.instance);
allDeserializers.put(Short.class.getName(), ShortSerializer.instance);
allDeserializers.put(Short.TYPE.getName(), ShortSerializer.instance);
// Numbers, limited length floating point
allDeserializers.put(Float.class.getName(), FloatSerializer.instance);
allDeserializers.put(Float.TYPE.getName(), FloatSerializer.instance);
allDeserializers.put(Double.class.getName(), DoubleSerializer.instance);
allDeserializers.put(Double.TYPE.getName(), DoubleSerializer.instance);
}
/*
/**********************************************************
/* Shared base class
/**********************************************************
*/
protected abstract static class Base<T> extends StdScalarSerializer<T>
implements ContextualSerializer
{
<CHANGES>
<CHANGEE>
protected final JsonParser.NumberType _numberType;
protected final String _schemaType;
protected final boolean _isInt;
protected Base(Class<?> cls, JsonParser.NumberType numberType, String schemaType) {
super(cls, false);
_numberType = numberType;
_schemaType = schemaType;
_isInt = (numberType == JsonParser.NumberType.INT)
|| (numberType == JsonParser.NumberType.LONG)
|| (numberType == JsonParser.NumberType.BIG_INTEGER)
;
}
case STRING:
return ToStringSerializer.instance;
default:
}
}
}
}
return this;
}
}
/*
/**********************************************************
/* Concrete serializers, numerics
/**********************************************************
*/
@JacksonStdImpl
public final static class ShortSerializer extends Base<Short>
{
<CHANGES>
<CHANGEE>
final static ShortSerializer instance = new ShortSerializer();
public ShortSerializer() { super(Short.class, JsonParser.NumberType.INT, "number"); }
@Override
<CHANGES>
<CHANGEE>
public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeNumber(value.shortValue());
}
}
/**
* This is the special serializer for regular {@link java.lang.Integer}s
* (and primitive ints)
*<p>
* Since this is one of<SCANS> return (BigInteger) n;
}
if (getNumberType() == NumberType.BIG_DECIMAL) {
return ((BigDecimal) n).toBigInteger();
}
// int/long is simple, but let's also just truncate float/double:
return BigInteger.valueOf(n.longValue());
}
@Override
public BigDecimal getDecimalValue() throws IOException, JsonParseException
{
Number n = getNumberValue();
if (n instanceof BigDecimal) {
return (BigDecimal) n;
}
switch (getNumberType()) {
case INT:
case LONG:
return BigDecimal.valueOf(n.longValue());
case BIG_INTEGER:
return new BigDecimal((BigInteger) n);
default:
}
// float or double
return BigDecimal.valueOf(n.doubleValue());
}
@Override
public double getDoubleValue() throws IOException, JsonParseException {
return getNumberValue().doubleValue();
}
@Override
public float getFloatValue() throws IOException, JsonParseException {
return getNumberValue().floatValue();
}
@Override
public int getIntValue() throws IOException, JsonParseException
{
// optimize common case:
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
return ((Number) _currentObject()).intValue();
}
return getNumberValue().intValue();
}
@Override
public long getLongValue() throws IOException, JsonParseException {
return getNumberValue().longValue();
}
@Override
public NumberType getNumberType() throws IOException, JsonParseException
{
Number n = getNumberValue();
if (n instanceof Integer) return NumberType.INT;
if (n instanceof Long) return NumberType.LONG;
if (n instanceof Double) return NumberType.DOUBLE;
if (n instanceof BigDecimal) return NumberType.BIG_DECIMAL;
if (n instanceof BigInteger) return NumberType.BIG_INTEGER;
if (n instanceof Float) return NumberType.FLOAT;
if (n instanceof Short) return NumberType.INT; // should be SHORT
return null;
}
@Override
public final Number getNumberValue() throws IOException, JsonParseException {
_checkIsNumber();
Object value = _currentObject();
if (value instanceof Number) {
return (Number) value;
}
// Difficult to really support numbers-as-Strings; but let's try.